| 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 |
|
| 27 |
$blocksFolder = GUTSLIDER_DIR . '/build/blocks'; |
| 28 |
|
| 29 |
if ( is_dir( $blocksFolder ) ) { |
| 30 |
|
| 31 |
$contents = scandir( $blocksFolder ); |
| 32 |
|
| 33 |
$blocks = array_filter( $contents, function( $item ) use ( $blocksFolder ) { |
| 34 |
$itemPath = $blocksFolder . DIRECTORY_SEPARATOR . $item; |
| 35 |
return is_dir( $itemPath ) && !in_array( $item, ['.', '..'] ); |
| 36 |
}); |
| 37 |
|
| 38 |
if( is_array( $blocks ) && ! empty( $blocks ) ) { |
| 39 |
foreach ( $blocks as $block ) { |
| 40 |
register_block_type( GUTSLIDER_DIR . '/build/blocks/' . $block ); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
new GutSlider_Register_Blocks(); // Initialize the class |