| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace FilterEverything\Filter; |
| 5 |
|
| 6 |
if ( ! defined('ABSPATH') ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
class Widgets |
| 11 |
{ |
| 12 |
function __construct(){ |
| 13 |
add_action( 'widgets_init', array( $this, 'register' ) ); |
| 14 |
add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hideFromLegacyWidgetBlock' ) ); |
| 15 |
} |
| 16 |
|
| 17 |
public function register(){ |
| 18 |
register_widget( '\FilterEverything\Filter\FiltersWidget' ); |
| 19 |
register_widget( '\FilterEverything\Filter\ChipsWidget' ); |
| 20 |
register_widget( '\FilterEverything\Filter\SortingWidget' ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Hides legacy widgets from the block-based widgets editor inserter and search, |
| 25 |
* because they are replaced with Gutenberg-style blocks there. |
| 26 |
* Already placed widget instances keep working and remain editable. |
| 27 |
*/ |
| 28 |
public function hideFromLegacyWidgetBlock( $widget_types ){ |
| 29 |
$widget_types[] = 'wpc_filters_widget'; |
| 30 |
$widget_types[] = 'wpc_chips_widget'; |
| 31 |
$widget_types[] = 'wpc_sorting_widget'; |
| 32 |
|
| 33 |
return $widget_types; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
new Widgets(); |