PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.10.0
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.10.0
3.1.0 3.0.0 2.13.2 2.13.1 2.13.0 trunk 1.0.0 2.1.0 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.1 2.5.3 2.5.4 2.5.5 2.6.1 All 56 releases
slider-blocks / includes / classes / class-register-blocks.php

class-register-blocks.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 2.10.0, at includes/classes/class-register-blocks.php

97 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Register Blocks
4 * @package GutSliderBlocks
5 */
6
7 if( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 if( ! class_exists( 'GutSliderBlocks_Registration' ) ) {
12
13 /**
14 * @since 1.0.0
15 * @package GutSlider Blocks
16 */
17 class GutSliderBlocks_Registration {
18
19 /**
20 * Constructor
21 *
22 * @since 1.0.0
23 * @return void
24 */
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() {
36 add_action( 'init', array ( $this, 'register_blocks' ) );
37 }
38
39 /**
40 * Register Blocks
41 *
42 * @since 1.0.0
43 * @return void
44 */
45 public function register_blocks() {
46
47 $blocks = get_option( 'gutslider_blocks', $this->get_gutslider_blocks() );
48
49 if ( ! empty( $blocks ) && is_array( $blocks ) ) {
50 foreach ( $blocks as $block ) {
51 $path = GUTSLIDER_DIR_PATH;
52
53 if( isset( $block['is_pro'] ) && $block['is_pro'] === true && defined( 'GUTSLIDER_PRO_PATH' ) ) {
54 $path = GUTSLIDER_PRO_PATH;
55 }
56
57 $block_name = trailingslashit( $path ) . 'build/blocks/' . $block['name'];
58 $block_key = $block['name'];
59
60 if($this->gutslider_is_block_enabled($block_key)) {
61 if( file_exists( $block_name ) ) {
62 // Check if the block is not already registered
63 if ( ! WP_Block_Type_Registry::get_instance()->is_registered( 'gutsliders/' . $block['name'] ) ) {
64 register_block_type( $block_name );
65 }
66 }
67 } else {
68 // Unregister the block if it is disabled
69 if( WP_Block_Type_Registry::get_instance()->is_registered( 'gutsliders/' . $block['name'] ) ) {
70 unregister_block_type( 'gutsliders/' . $block['name'] );
71 }
72 }
73 }
74 }
75 }
76
77 /**
78 * Get GutSlider Blocks
79 */
80 public function get_gutslider_blocks() {
81 return require GUTSLIDER_DIR_PATH . 'includes/api/blocks.php';
82 }
83
84 /**
85 * Check if a block is enabled
86 */
87 public function gutslider_is_block_enabled($block_name) {
88 $option_key = 'gut_' . str_replace('-', '_', $block_name);
89 return (bool) get_option($option_key, true);
90 }
91
92
93 }
94
95 }
96
97 new GutSliderBlocks_Registration(); // Initialize the class.