| @@ -22,13 +22,19 @@ | ||
| 22 | 22 | * @since 1.0.0 |
| 23 | 23 | * @return void |
| 24 | 24 | */ |
| 25 | 25 | public function __construct() { |
| 26 | + $this->init(); | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Initialize the Class | |
| 31 | + * | |
| 32 | + * @since 1.0.0 | |
| 33 | + * @return void | |
| 34 | + */ | |
| 35 | + private function init() { | |
| 26 | 36 | add_action( 'init', array ( $this, 'register_blocks' ) ); |
| 27 | - // check block theme | |
| 28 | - if( ! wp_is_block_theme() ) { | |
| 29 | - add_filter( 'should_load_separate_core_block_assets', '__return_true' ); | |
| 30 | - } | |
| 31 | 37 | } |
| 32 | 38 | |
| 33 | 39 | /** |
| 34 | 40 | * Register Blocks |
| @@ -48,22 +54,22 @@ | ||
| 48 | 54 | $path = GUTSLIDER_PRO_PATH; |
| 49 | 55 | } |
| 50 | 56 | |
| 51 | 57 | $block_name = trailingslashit( $path ) . 'build/blocks/' . $block['name']; |
| 52 | - $block_key = $block['name']; | |
| 53 | - | |
| 54 | - if($this->gutslider_is_block_enabled($block_key)) { | |
| 58 | + $full_block_name = 'gutsliders/' . $block['name']; | |
| 59 | + | |
| 60 | + if ( isset( $block['active'] ) && $block['active'] === false ) { | |
| 61 | + // Check if the block type is registered before trying to unregister it | |
| 62 | + if( WP_Block_Type_Registry::get_instance()->is_registered( $full_block_name ) ) { | |
| 63 | + unregister_block_type( $full_block_name ); | |
| 64 | + } | |
| 65 | + } else { | |
| 55 | 66 | if( file_exists( $block_name ) ) { |
| 56 | 67 | // Check if the block is not already registered |
| 57 | - if ( ! WP_Block_Type_Registry::get_instance()->is_registered( 'gutsliders/' . $block['name'] ) ) { | |
| 68 | + if ( ! WP_Block_Type_Registry::get_instance()->is_registered( $full_block_name ) ) { | |
| 58 | 69 | register_block_type( $block_name ); |
| 59 | 70 | } |
| 60 | 71 | } |
| 61 | - } else { | |
| 62 | - // Unregister the block if it is disabled | |
| 63 | - if( WP_Block_Type_Registry::get_instance()->is_registered( 'gutsliders/' . $block['name'] ) ) { | |
| 64 | - unregister_block_type( 'gutsliders/' . $block['name'] ); | |
| 65 | - } | |
| 66 | 72 | } |
| 67 | 73 | } |
| 68 | 74 | } |
| 69 | 75 | } |
| @@ -72,16 +78,8 @@ | ||
| 72 | 78 | * Get GutSlider Blocks |
| 73 | 79 | */ |
| 74 | 80 | public function get_gutslider_blocks() { |
| 75 | 81 | return require GUTSLIDER_DIR_PATH . 'includes/api/blocks.php'; |
| 76 | - } | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * Check if a block is enabled | |
| 80 | - */ | |
| 81 | - public function gutslider_is_block_enabled($block_name) { | |
| 82 | - $option_key = 'gut_' . str_replace('-', '_', $block_name); | |
| 83 | - return (bool) get_option($option_key, true); | |
| 84 | 82 | } |
| 85 | 83 | |
| 86 | 84 | |
| 87 | 85 | } |