| 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 |
*/ |
| 16 |
public function __construct() { |
| 17 |
$filter = version_compare( $GLOBALS['wp_version'], '5.7', '<' ) ? 'block_categories' : 'block_categories_all'; |
| 18 |
add_filter( $filter, [ $this, 'register_block_category' ], 10, 2 ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Register Block Category |
| 23 |
* @param array $categories |
| 24 |
* @param WP_Post $post |
| 25 |
* @return array |
| 26 |
*/ |
| 27 |
public function register_block_category( $categories, $post ) { |
| 28 |
$new_category = array( |
| 29 |
'slug' => 'slider-blocks', |
| 30 |
'title' => __( 'GutSlider Blocks', 'slider-blocks' ), |
| 31 |
); |
| 32 |
return array_merge( array( $new_category ), $categories ); |
| 33 |
} |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
new GutSlider_Blocks_Category(); // Initialize the class |
| 38 |
} |
| 39 |
|