Move widget registration to own function/file - avoid register_widget in class files
This commit is contained in:
parent
f088f81dcf
commit
dd53f8e730
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit;
|
||||
}
|
||||
|
||||
// Include core functions (available in both admin and frontend)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce Widget Functions
|
||||
*
|
||||
* Widget related functions and widget registration
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Core
|
||||
* @package WooCommerce/Functions
|
||||
* @version 2.3.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Include widget classes
|
||||
include_once( 'abstracts/abstract-wc-widget.php' );
|
||||
include_once( 'widgets/class-wc-widget-cart.php' );
|
||||
include_once( 'widgets/class-wc-widget-layered-nav-filters.php' );
|
||||
include_once( 'widgets/class-wc-widget-layered-nav.php' );
|
||||
include_once( 'widgets/class-wc-widget-price-filter.php' );
|
||||
include_once( 'widgets/class-wc-widget-product-categories.php' );
|
||||
include_once( 'widgets/class-wc-widget-product-search.php' );
|
||||
include_once( 'widgets/class-wc-widget-product-tag-cloud.php' );
|
||||
include_once( 'widgets/class-wc-widget-products.php' );
|
||||
include_once( 'widgets/class-wc-widget-recent-reviews.php' );
|
||||
include_once( 'widgets/class-wc-widget-recently-viewed.php' );
|
||||
include_once( 'widgets/class-wc-widget-top-rated-products.php' );
|
||||
|
||||
/**
|
||||
* Register Widgets
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
function wc_register_widgets() {
|
||||
register_widget( 'WC_Widget_Cart' );
|
||||
register_widget( 'WC_Widget_Layered_Nav_Filters' );
|
||||
register_widget( 'WC_Widget_Layered_Nav' );
|
||||
register_widget( 'WC_Widget_Price_Filter' );
|
||||
register_widget( 'WC_Widget_Product_Categories' );
|
||||
register_widget( 'WC_Widget_Product_Search' );
|
||||
register_widget( 'WC_Widget_Product_Tag_Cloud' );
|
||||
register_widget( 'WC_Widget_Products' );
|
||||
register_widget( 'WC_Widget_Recent_Reviews' );
|
||||
register_widget( 'WC_Widget_Recently_Viewed' );
|
||||
register_widget( 'WC_Widget_Top_Rated_Products' );
|
||||
}
|
||||
add_action( 'widgets_init', 'wc_register_widgets' );
|
|
@ -74,5 +74,3 @@ class WC_Widget_Cart extends WC_Widget {
|
|||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Cart' );
|
||||
|
|
|
@ -99,5 +99,3 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Layered_Nav_Filters' );
|
||||
|
|
|
@ -414,5 +414,3 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Layered_Nav' );
|
||||
|
|
|
@ -180,5 +180,3 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Price_Filter' );
|
||||
|
|
|
@ -236,5 +236,3 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Product_Categories' );
|
||||
|
|
|
@ -52,5 +52,3 @@ class WC_Widget_Product_Search extends WC_Widget {
|
|||
$this->widget_end( $args );
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Product_Search' );
|
||||
|
|
|
@ -73,5 +73,3 @@ class WC_Widget_Product_Tag_Cloud extends WC_Widget {
|
|||
return 'product_tag';
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Product_Tag_Cloud' );
|
||||
|
|
|
@ -189,5 +189,3 @@ class WC_Widget_Products extends WC_Widget {
|
|||
echo $this->cache_widget( $args, ob_get_clean() );
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Products' );
|
||||
|
|
|
@ -102,5 +102,3 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
|
|||
$this->cache_widget( $args, $content );
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Recent_Reviews' );
|
||||
|
|
|
@ -96,5 +96,3 @@ class WC_Widget_Recently_Viewed extends WC_Widget {
|
|||
echo $content;
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'WC_Widget_Recently_Viewed' );
|
||||
|
|
|
@ -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' );
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue