From dd53f8e730558f7698df22d502a57dba3e13010a Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 20 Nov 2014 20:56:24 +0000 Subject: [PATCH] Move widget registration to own function/file - avoid register_widget in class files --- includes/wc-core-functions.php | 2 +- includes/wc-widget-functions.php | 49 +++++++++++++++++++ includes/widgets/class-wc-widget-cart.php | 2 - .../class-wc-widget-layered-nav-filters.php | 2 - .../widgets/class-wc-widget-layered-nav.php | 2 - .../widgets/class-wc-widget-price-filter.php | 2 - .../class-wc-widget-product-categories.php | 2 - .../class-wc-widget-product-search.php | 2 - .../class-wc-widget-product-tag-cloud.php | 2 - includes/widgets/class-wc-widget-products.php | 2 - .../class-wc-widget-recent-reviews.php | 2 - .../class-wc-widget-recently-viewed.php | 2 - .../class-wc-widget-top-rated-products.php | 2 - woocommerce.php | 20 +------- 14 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 includes/wc-widget-functions.php diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index b7ad9459685..5b07ea74042 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -11,7 +11,7 @@ */ if ( ! defined( 'ABSPATH' ) ) { - exit; // Exit if accessed directly + exit; } // Include core functions (available in both admin and frontend) diff --git a/includes/wc-widget-functions.php b/includes/wc-widget-functions.php new file mode 100644 index 00000000000..6317fdd8d30 --- /dev/null +++ b/includes/wc-widget-functions.php @@ -0,0 +1,49 @@ +widget_end( $args ); } } - -register_widget( 'WC_Widget_Cart' ); diff --git a/includes/widgets/class-wc-widget-layered-nav-filters.php b/includes/widgets/class-wc-widget-layered-nav-filters.php index 521a2e34979..cb790aea81f 100644 --- a/includes/widgets/class-wc-widget-layered-nav-filters.php +++ b/includes/widgets/class-wc-widget-layered-nav-filters.php @@ -99,5 +99,3 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget { } } } - -register_widget( 'WC_Widget_Layered_Nav_Filters' ); diff --git a/includes/widgets/class-wc-widget-layered-nav.php b/includes/widgets/class-wc-widget-layered-nav.php index 4b91b85ffde..3efa7189234 100644 --- a/includes/widgets/class-wc-widget-layered-nav.php +++ b/includes/widgets/class-wc-widget-layered-nav.php @@ -414,5 +414,3 @@ class WC_Widget_Layered_Nav extends WC_Widget { } } } - -register_widget( 'WC_Widget_Layered_Nav' ); diff --git a/includes/widgets/class-wc-widget-price-filter.php b/includes/widgets/class-wc-widget-price-filter.php index 973b00eaa17..e77d600b4f0 100644 --- a/includes/widgets/class-wc-widget-price-filter.php +++ b/includes/widgets/class-wc-widget-price-filter.php @@ -180,5 +180,3 @@ class WC_Widget_Price_Filter extends WC_Widget { $this->widget_end( $args ); } } - -register_widget( 'WC_Widget_Price_Filter' ); diff --git a/includes/widgets/class-wc-widget-product-categories.php b/includes/widgets/class-wc-widget-product-categories.php index 0a4016eef5b..69952b4f9d5 100644 --- a/includes/widgets/class-wc-widget-product-categories.php +++ b/includes/widgets/class-wc-widget-product-categories.php @@ -236,5 +236,3 @@ class WC_Widget_Product_Categories extends WC_Widget { $this->widget_end( $args ); } } - -register_widget( 'WC_Widget_Product_Categories' ); diff --git a/includes/widgets/class-wc-widget-product-search.php b/includes/widgets/class-wc-widget-product-search.php index 12039f58541..399a8f9a16c 100644 --- a/includes/widgets/class-wc-widget-product-search.php +++ b/includes/widgets/class-wc-widget-product-search.php @@ -52,5 +52,3 @@ class WC_Widget_Product_Search extends WC_Widget { $this->widget_end( $args ); } } - -register_widget( 'WC_Widget_Product_Search' ); diff --git a/includes/widgets/class-wc-widget-product-tag-cloud.php b/includes/widgets/class-wc-widget-product-tag-cloud.php index 003cc218e27..e199fab73e4 100644 --- a/includes/widgets/class-wc-widget-product-tag-cloud.php +++ b/includes/widgets/class-wc-widget-product-tag-cloud.php @@ -73,5 +73,3 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget { return 'product_tag'; } } - -register_widget( 'WC_Widget_Product_Tag_Cloud' ); diff --git a/includes/widgets/class-wc-widget-products.php b/includes/widgets/class-wc-widget-products.php index 951bbc1ed28..f9e552c8e74 100644 --- a/includes/widgets/class-wc-widget-products.php +++ b/includes/widgets/class-wc-widget-products.php @@ -189,5 +189,3 @@ class WC_Widget_Products extends WC_Widget { echo $this->cache_widget( $args, ob_get_clean() ); } } - -register_widget( 'WC_Widget_Products' ); diff --git a/includes/widgets/class-wc-widget-recent-reviews.php b/includes/widgets/class-wc-widget-recent-reviews.php index 6c2dcc228f6..84f329ef7fb 100644 --- a/includes/widgets/class-wc-widget-recent-reviews.php +++ b/includes/widgets/class-wc-widget-recent-reviews.php @@ -102,5 +102,3 @@ class WC_Widget_Recent_Reviews extends WC_Widget { $this->cache_widget( $args, $content ); } } - -register_widget( 'WC_Widget_Recent_Reviews' ); diff --git a/includes/widgets/class-wc-widget-recently-viewed.php b/includes/widgets/class-wc-widget-recently-viewed.php index 5ef6bf22ebf..a5d6f1429be 100644 --- a/includes/widgets/class-wc-widget-recently-viewed.php +++ b/includes/widgets/class-wc-widget-recently-viewed.php @@ -96,5 +96,3 @@ class WC_Widget_Recently_Viewed extends WC_Widget { echo $content; } } - -register_widget( 'WC_Widget_Recently_Viewed' ); diff --git a/includes/widgets/class-wc-widget-top-rated-products.php b/includes/widgets/class-wc-widget-top-rated-products.php index c48d446493c..e6904028986 100644 --- a/includes/widgets/class-wc-widget-top-rated-products.php +++ b/includes/widgets/class-wc-widget-top-rated-products.php @@ -99,5 +99,3 @@ class WC_Widget_Top_Rated_Products extends WC_Widget { $this->cache_widget( $args, $content ); } } - -register_widget( 'WC_Widget_Top_Rated_Products' ); diff --git a/woocommerce.php b/woocommerce.php index 8991e44fef0..e909e5ed0c7 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -133,7 +133,6 @@ final class WooCommerce { add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 ); add_action( 'init', array( $this, 'init' ), 0 ); add_action( 'init', array( 'WC_Shortcodes', 'init' ) ); - add_action( 'widgets_init', array( $this, 'widget_includes' ) ); // Loaded action do_action( 'woocommerce_loaded' ); @@ -196,6 +195,7 @@ final class WooCommerce { private function includes() { include_once( 'includes/class-wc-autoloader.php' ); include_once( 'includes/wc-core-functions.php' ); + include_once( 'includes/wc-widget-functions.php' ); include_once( 'includes/class-wc-install.php' ); include_once( 'includes/class-wc-download-handler.php' ); include_once( 'includes/class-wc-comments.php' ); @@ -275,24 +275,6 @@ final class WooCommerce { } } - /** - * Include core widgets - */ - public function widget_includes() { - include_once( 'includes/abstracts/abstract-wc-widget.php' ); - include_once( 'includes/widgets/class-wc-widget-cart.php' ); - include_once( 'includes/widgets/class-wc-widget-layered-nav-filters.php' ); - include_once( 'includes/widgets/class-wc-widget-layered-nav.php' ); - include_once( 'includes/widgets/class-wc-widget-price-filter.php' ); - include_once( 'includes/widgets/class-wc-widget-product-categories.php' ); - include_once( 'includes/widgets/class-wc-widget-product-search.php' ); - include_once( 'includes/widgets/class-wc-widget-product-tag-cloud.php' ); - include_once( 'includes/widgets/class-wc-widget-products.php' ); - include_once( 'includes/widgets/class-wc-widget-recent-reviews.php' ); - include_once( 'includes/widgets/class-wc-widget-recently-viewed.php' ); - include_once( 'includes/widgets/class-wc-widget-top-rated-products.php' ); - } - /** * Init WooCommerce when WordPress Initialises. */