| 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 |
$blocksFolder = trailingslashit( GUTSLIDER_DIR ) . '/build/blocks'; |
| 27 |
|
| 28 |
if ( ! is_dir( $blocksFolder ) ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
$active_blocks = []; |
| 33 |
|
| 34 |
$content_slider = get_option('gut_fixed_content_slider', true); |
| 35 |
$any_content_slider = get_option('gut_any_content_slider', true); |
| 36 |
$testimonial_slider = get_option('gut_testimonial_slider', true); |
| 37 |
|
| 38 |
$contents = scandir( $blocksFolder ); |
| 39 |
|
| 40 |
foreach ( $contents as $item ) { |
| 41 |
if ( in_array( $item, ['.', '..'] ) ) { |
| 42 |
continue; |
| 43 |
} |
| 44 |
|
| 45 |
$itemPath = $blocksFolder . DIRECTORY_SEPARATOR . $item; |
| 46 |
|
| 47 |
if ( is_dir( $itemPath ) ) { |
| 48 |
if ( ( ! $content_slider && $item === 'content-slider' ) || ( ! $any_content_slider && $item === 'any-content' ) || ( ! $testimonial_slider && $item === 'testimonial-slider' ) ) { |
| 49 |
continue; |
| 50 |
} |
| 51 |
|
| 52 |
$active_blocks[] = $item; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if ( ! empty( $active_blocks ) ) { |
| 57 |
foreach ( $active_blocks as $block ) { |
| 58 |
register_block_type( trailingslashit( GUTSLIDER_DIR ) . '/build/blocks/' . $block); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
new GutSlider_Register_Blocks(); // Initialize the class |