| 1 |
<?php |
| 2 |
/** |
| 3 |
* Widget manager |
| 4 |
* |
| 5 |
* @package wpstream-theme |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Class is used to register widgets |
| 15 |
*/ |
| 16 |
if ( ! class_exists( 'Wpstream_Widget_Manager' ) ) { |
| 17 |
/** |
| 18 |
* Class for managing custom widgets. |
| 19 |
*/ |
| 20 |
class Wpstream_Widget_Manager { |
| 21 |
/** |
| 22 |
* Constructor function. |
| 23 |
*/ |
| 24 |
public function __construct() { |
| 25 |
add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
| 26 |
|
| 27 |
add_filter( 'woocommerce_before_widget_product_list', array( $this, 'remove_class' ) ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Remove class from ul. |
| 32 |
* |
| 33 |
* @return string The modified ul tag. |
| 34 |
*/ |
| 35 |
public function remove_class() { |
| 36 |
return "<ul class=''>"; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Register custom widgets. |
| 41 |
*/ |
| 42 |
public function register_widgets() { |
| 43 |
require_once 'class-wpstream-widget-base.php'; |
| 44 |
|
| 45 |
$widgets = glob( __DIR__ . '/*-widget.php' ); |
| 46 |
|
| 47 |
if ( ! empty( $widgets ) ) { |
| 48 |
foreach ( $widgets as $file ) { |
| 49 |
if ( file_exists( $file ) ) { |
| 50 |
$file_name = pathinfo( $file, PATHINFO_FILENAME ); |
| 51 |
$class_name = implode( '_', array_map( 'ucwords', array_slice( explode( '-', $file_name ), 1 ) ) ); |
| 52 |
require_once $file; |
| 53 |
|
| 54 |
if ( class_exists( $class_name ) && is_a( $class_name, 'Wpstream_Widget_Base', true ) ) { |
| 55 |
// Unregister widgets. |
| 56 |
foreach ( $class_name::get_widgets_for_unregister() as $widget ) { |
| 57 |
unregister_widget( $widget ); |
| 58 |
} |
| 59 |
register_widget( $class_name ); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
( new Wpstream_Widget_Manager() ); |
| 69 |
|