| 1 |
<?php |
| 2 |
declare( strict_types=1 ); |
| 3 |
|
| 4 |
namespace GutSlider\Blocks; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* Registers the custom block category for GutSlider blocks. |
| 12 |
* |
| 13 |
* Adds a "GutSlider Blocks" category to the block editor so that |
| 14 |
* all slider blocks are grouped together in the inserter. |
| 15 |
* |
| 16 |
* @package GutSlider\Blocks |
| 17 |
* @since 3.0.0 |
| 18 |
*/ |
| 19 |
final class BlocksCategory { |
| 20 |
|
| 21 |
/** |
| 22 |
* Constructor. |
| 23 |
* |
| 24 |
* Registers the block_categories_all filter hook. |
| 25 |
* |
| 26 |
* @since 3.0.0 |
| 27 |
*/ |
| 28 |
public function __construct() { |
| 29 |
add_filter( 'block_categories_all', array( $this, 'register_block_category' ), 10, 2 ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Register the GutSlider block category. |
| 34 |
* |
| 35 |
* Prepends the slider-blocks category to the list of available |
| 36 |
* block categories in the editor. |
| 37 |
* |
| 38 |
* @since 3.0.0 |
| 39 |
* |
| 40 |
* @param array<int, array<string, mixed>> $categories Existing block categories. |
| 41 |
* @param \WP_Block_Editor_Context $context The block editor context. |
| 42 |
* @return array<int, array<string, mixed>> Modified block categories. |
| 43 |
*/ |
| 44 |
// public function register_block_category( array $categories, \WP_Block_Editor_Context $context ): array { |
| 45 |
// $new_category = array( |
| 46 |
// 'slug' => 'slider-blocks', |
| 47 |
// 'title' => __( 'GutSlider Blocks', 'slider-blocks' ), |
| 48 |
// ); |
| 49 |
|
| 50 |
// return array_merge( array( $new_category ), $categories ); |
| 51 |
// } |
| 52 |
|
| 53 |
public function register_block_category( $categories, $post ) { |
| 54 |
|
| 55 |
array_unshift( $categories, array( |
| 56 |
'slug' => 'slider-blocks', |
| 57 |
'title' => __( 'GutSlider Blocks', 'slider-blocks' ), |
| 58 |
) ); |
| 59 |
|
| 60 |
return $categories; |
| 61 |
} |
| 62 |
} |
| 63 |
|