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