| 1 |
<?php |
| 2 |
/** |
| 3 |
* Register Blocks |
| 4 |
* @package GutSliderBlocks |
| 5 |
*/ |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. |
| 8 |
|
| 9 |
if( ! class_exists( 'GutSlider_Register_Blocks' ) ) { |
| 10 |
|
| 11 |
class GutSlider_Register_Blocks { |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor |
| 15 |
* return void |
| 16 |
*/ |
| 17 |
public function __construct() { |
| 18 |
add_action( 'init', [ $this, 'register_blocks' ] ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Register Blocks |
| 23 |
* return void |
| 24 |
*/ |
| 25 |
public function register_blocks() { |
| 26 |
$blocks = [ |
| 27 |
'content-slider', |
| 28 |
'any-content', |
| 29 |
'testimonial-slider', |
| 30 |
'post-slider', |
| 31 |
'photo-carousel' |
| 32 |
]; |
| 33 |
|
| 34 |
$active_blocks = []; |
| 35 |
|
| 36 |
$block_options = [ |
| 37 |
'content-slider' => 'gut_fixed_content_slider', |
| 38 |
'any-content' => 'gut_any_content_slider', |
| 39 |
'testimonial-slider' => 'gut_testimonial_slider', |
| 40 |
'post-slider' => 'gut_post_slider', |
| 41 |
'photo-carousel' => 'gut_photo_carousel', |
| 42 |
]; |
| 43 |
|
| 44 |
foreach ($blocks as $block) { |
| 45 |
$option_name = $block_options[$block]; |
| 46 |
$block_enabled = get_option($option_name, true); |
| 47 |
|
| 48 |
if ($block_enabled) { |
| 49 |
$active_blocks[] = $block; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
if ( ! empty( $active_blocks ) ) { |
| 54 |
foreach ( $active_blocks as $block ) { |
| 55 |
register_block_type( trailingslashit( GUTSLIDER_DIR ) . '/build/blocks/' . $block); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
new GutSlider_Register_Blocks(); // Initialize the class |