| 1 |
<?php |
| 2 |
/** |
| 3 |
* Register Blocks Category |
| 4 |
* @package GutSliderBlocks |
| 5 |
*/ |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. |
| 8 |
|
| 9 |
if( ! class_exists( 'GutSlider_Blocks_Category' ) ) { |
| 10 |
|
| 11 |
class GutSlider_Blocks_Category { |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor |
| 15 |
* return void |
| 16 |
*/ |
| 17 |
public function __construct() { |
| 18 |
if( version_compare( $GLOBALS['wp_version'], '5.7', '<' ) ) { |
| 19 |
add_filter( 'block_categories', [ $this, 'register_block_category' ], 10, 2, 9999 ); |
| 20 |
} else { |
| 21 |
add_filter( 'block_categories_all', [ $this, 'register_block_category' ], 10, 2, 9999 ); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Register Block Category |
| 27 |
* return array |
| 28 |
*/ |
| 29 |
public function register_block_category( $categories, $post ) { |
| 30 |
return array_merge( |
| 31 |
array( |
| 32 |
array( |
| 33 |
'slug' => 'slider-blocks', |
| 34 |
'title' => __( 'GutSlider Blocks', 'slider-blocks' ), |
| 35 |
), |
| 36 |
), |
| 37 |
$categories, |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
new GutSlider_Blocks_Category(); // Initialize the class |