Skip to content

Commit d98fe05

Browse files
Clean up integrations a little.
1 parent f8f88e4 commit d98fe05

File tree

9 files changed

+156
-95
lines changed

9 files changed

+156
-95
lines changed

app/class-integration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ abstract class Integration {
5656
*/
5757
protected $dependencies;
5858

59+
/**
60+
* Additional functional files.
61+
*
62+
* @var array $helper_files
63+
* @since 2.2.0
64+
*/
65+
protected $helper_files = [];
66+
5967
/**
6068
* Additional inline CSS configuration items.
6169
*
@@ -77,6 +85,10 @@ public function __construct( $slug, $dependencies ) {
7785
$this->dependencies = $dependencies;
7886
$this->local_path = trailingslashit( '/app/integrations' ) . $slug;
7987
$this->dir = get_template_directory() . $this->get_local_path();
88+
89+
foreach ( $this->helper_files as $name ) {
90+
include_once trailingslashit( $this->get_dir() ) . $name . '.php';
91+
}
8092
}
8193

8294
/**

app/customize/type-functions.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ function bigbox_get_google_font_family_string() {
9898
* @return mixed URL if needed. False otherwise.
9999
*/
100100
function bigbox_get_google_fonts_url() {
101-
if ( ! bigbox_has_google_fonts() ) {
102-
return false;
103-
}
104-
105101
$family_string = bigbox_get_google_font_family_string();
106102

107103
if ( ! $family_string ) {

app/integrations/facetwp/class-facetwp.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@
2626
*/
2727
class FacetWP extends Integration implements Registerable, Service {
2828

29+
/**
30+
* Additional functional files.
31+
*
32+
* @var array $helper_files
33+
* @since 2.2.0
34+
*/
35+
protected $helper_files = [
36+
'template-hooks',
37+
'template-functions',
38+
'default-facets',
39+
'customize',
40+
];
41+
2942
/**
3043
* Additional inline CSS configuration items.
3144
*
@@ -43,11 +56,6 @@ class FacetWP extends Integration implements Registerable, Service {
4356
*/
4457
public function register() {
4558
add_filter( 'bigbox_customize_inline_css_configs', [ $this, 'inline_css_configs' ] );
46-
47-
include_once $this->get_dir() . '/template-hooks.php';
48-
include_once $this->get_dir() . '/template-functions.php';
49-
include_once $this->get_dir() . '/default-facets.php';
50-
include_once $this->get_dir() . '/customize.php';
5159
}
5260

5361
}

app/integrations/woocommerce-bookings/class-woocommerce-bookings.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
*/
2727
class WooCommerce_Bookings extends Integration implements Registerable, Service {
2828

29+
/**
30+
* Additional functional files.
31+
*
32+
* @var array $helper_files
33+
* @since 2.2.0
34+
*/
35+
protected $helper_files = [
36+
'template-hooks',
37+
'template-functions',
38+
];
39+
2940
/**
3041
* Additional inline CSS configuration items.
3142
*
@@ -47,9 +58,6 @@ class WooCommerce_Bookings extends Integration implements Registerable, Service
4758
*/
4859
public function register() {
4960
add_filter( 'bigbox_customize_inline_css_configs', [ $this, 'inline_css_configs' ] );
50-
51-
include_once $this->get_dir() . '/template-hooks.php';
52-
include_once $this->get_dir() . '/template-functions.php';
5361
}
5462

5563
}

app/integrations/woocommerce-brands/class-woocommerce-brands.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@
2626
*/
2727
class WooCommerce_Brands extends Integration implements Registerable, Service {
2828

29+
/**
30+
* Additional functional files.
31+
*
32+
* @var array $helper_files
33+
* @since 2.2.0
34+
*/
35+
protected $helper_files = [
36+
'template-hooks',
37+
'template-functions',
38+
];
39+
2940
/**
3041
* Connect to WordPress.
3142
*
3243
* @since 1.0.0
3344
*/
34-
public function register() {
35-
include_once $this->get_dir() . '/template-hooks.php';
36-
include_once $this->get_dir() . '/template-functions.php';
37-
}
45+
public function register() {}
3846

3947
}

app/integrations/woocommerce-product-vendors/class-woocommerce-product-vendors.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@
2626
*/
2727
class WooCommerce_Product_Vendors extends Integration implements Registerable, Service {
2828

29+
/**
30+
* Additional functional files.
31+
*
32+
* @var array $helper_files
33+
* @since 2.2.0
34+
*/
35+
protected $helper_files = [
36+
'template-hooks',
37+
'template-functions',
38+
];
39+
2940
/**
3041
* Connect to WordPress.
3142
*
32-
* @since 1.14.0
43+
* @since 1.0.0
3344
*/
34-
public function register() {
35-
include_once $this->get_dir() . '/template-hooks.php';
36-
include_once $this->get_dir() . '/template-functions.php';
37-
}
45+
public function register() {}
3846

3947
}

app/integrations/woocommerce/class-woocommerce.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@
2626
*/
2727
class WooCommerce extends Integration implements Registerable, Service {
2828

29+
/**
30+
* Additional functional files.
31+
*
32+
* @var array $helper_files
33+
* @since 2.2.0
34+
*/
35+
protected $helper_files = [
36+
'wc-template-functions',
37+
'starter-content',
38+
'cart',
39+
'checkout',
40+
'widgets',
41+
'emails',
42+
'nav-menus',
43+
'page-templates',
44+
'template-tags',
45+
'template-functions',
46+
'template-hooks',
47+
];
48+
2949
/**
3050
* Additional inline CSS configuration items.
3151
*
@@ -44,20 +64,6 @@ class WooCommerce extends Integration implements Registerable, Service {
4464
public function register() {
4565
add_filter( 'bigbox_customize_inline_css_configs', [ $this, 'inline_css_configs' ] );
4666
add_action( 'after_setup_theme', [ $this, 'add_theme_support' ] );
47-
48-
include_once $this->get_dir() . '/wc-template-functions.php';
49-
50-
include_once $this->get_dir() . '/starter-content.php';
51-
include_once $this->get_dir() . '/cart.php';
52-
include_once $this->get_dir() . '/checkout.php';
53-
include_once $this->get_dir() . '/widgets.php';
54-
include_once $this->get_dir() . '/emails.php';
55-
include_once $this->get_dir() . '/nav-menus.php';
56-
include_once $this->get_dir() . '/page-templates.php';
57-
include_once $this->get_dir() . '/customize.php';
58-
59-
include_once $this->get_dir() . '/template-functions.php';
60-
include_once $this->get_dir() . '/template-hooks.php';
6167
}
6268

6369
/**

app/integrations/woocommerce/template-functions.php

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* WooCommerce template functions.
3+
* WooCommerce template functions (callbacks for actions).
44
*
55
* @since 1.0.0
66
*
@@ -29,17 +29,6 @@ function bigbox_woocommerce_enqueue_styles( $styles ) {
2929
return $styles;
3030
}
3131

32-
/**
33-
* Look in the integration for templates.
34-
*
35-
* @since 1.0.0
36-
*
37-
* @return string
38-
*/
39-
function bigbox_woocommerce_template_path() {
40-
return 'resources/views/integrations/woocommerce/';
41-
}
42-
4332
/**
4433
* WooCommerce specific scripts.
4534
*
@@ -110,54 +99,6 @@ function bigbox_woocommerce_js_settings( $settings ) {
11099
return $settings;
111100
}
112101

113-
/**
114-
* Determine if we are on a shop page.
115-
*
116-
* By default this checks for:
117-
*
118-
* - WooCommerce shop page.
119-
* - Dynamic shop page template.
120-
*
121-
* @since 1.0.0
122-
*
123-
* @return bool
124-
*/
125-
function bigbox_is_shop() {
126-
$is_shop = (
127-
( is_shop() || is_product_taxonomy() )
128-
|| is_page_template( bigbox_woocommerce_dynamic_shop_page_template() )
129-
);
130-
131-
/**
132-
* Filters a conditional to determine if the current page is a shop.
133-
*
134-
* @since 1.0.0
135-
*
136-
* @param bool $is_shop If the current page should be considered a shop.
137-
*/
138-
return apply_filters( 'bigbox_is_shop', $is_shop );
139-
}
140-
141-
/**
142-
* Determine if a WooCommerce thumbnail should display.
143-
*
144-
* @since 1.0.0
145-
*
146-
* @param WC_Product $product WooCommerce product. Attempts to find global if null.
147-
* @return mixed String of HTML for an image or null.
148-
*/
149-
function bigbox_woocommerce_has_product_image( $product = null ) {
150-
if ( ! $product ) {
151-
$product = wc_get_product( get_the_ID() );
152-
}
153-
154-
if ( ! get_theme_mod( 'display-image-placeholders', true ) ) {
155-
return '' !== $product->get_image_id();
156-
}
157-
158-
return '' !== $product->get_image();
159-
}
160-
161102
/**
162103
* Load a separate view for the navbar search.
163104
*
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* WooCommerce template tags.
4+
*
5+
* @since 1.0.0
6+
*
7+
* @package BigBox
8+
* @category Integration
9+
* @author Spencer Finnell
10+
*/
11+
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit; // Exit if accessed directly.
14+
}
15+
16+
/**
17+
* Return Woocommerce view path.
18+
*
19+
* @since 1.0.0
20+
*
21+
* @return string
22+
*/
23+
function bigbox_woocommerce_template_path() {
24+
return 'resources/views/integrations/woocommerce/';
25+
}
26+
27+
/**
28+
* Determine if we are on a shop page.
29+
*
30+
* By default this checks for:
31+
*
32+
* - WooCommerce shop page.
33+
* - Dynamic shop page template.
34+
*
35+
* @since 1.0.0
36+
*
37+
* @return bool
38+
*/
39+
function bigbox_is_shop() {
40+
$is_shop = (
41+
( is_shop() || is_product_taxonomy() )
42+
|| is_page_template( bigbox_woocommerce_dynamic_shop_page_template() )
43+
);
44+
45+
/**
46+
* Filters a conditional to determine if the current page is a shop.
47+
*
48+
* @since 1.0.0
49+
*
50+
* @param bool $is_shop If the current page should be considered a shop.
51+
*/
52+
return apply_filters( 'bigbox_is_shop', $is_shop );
53+
}
54+
55+
/**
56+
* Determine if a WooCommerce thumbnail should display.
57+
*
58+
* @since 1.0.0
59+
*
60+
* @param WC_Product $product WooCommerce product. Attempts to find global if null.
61+
* @return mixed String of HTML for an image or null.
62+
*/
63+
function bigbox_woocommerce_has_product_image( $product = null ) {
64+
if ( ! $product ) {
65+
$product = wc_get_product( get_the_ID() );
66+
}
67+
68+
if ( ! get_theme_mod( 'display-image-placeholders', true ) ) {
69+
return '' !== $product->get_image_id();
70+
}
71+
72+
return '' !== $product->get_image();
73+
}
74+

0 commit comments

Comments
 (0)