# slider-blocks/2.2.1/includes/classes/class-register-blocks.php

GutSlider – All in One Slider and Carousel Blocks for Gutenberg, version 2.2.1. 65 lines.

- Page: https://pluginprobe.com/plugins/slider-blocks/2.2.1/code/includes/classes/class-register-blocks.php
- Raw: https://pluginprobe.com/plugins/slider-blocks/2.2.1/raw/includes/classes/class-register-blocks.php
- Modified: 2023-10-07T15:12:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/slider-blocks/2.2.1/code/includes/classes/class-register-blocks.php#L10-L20`.

```php
<?php
/**
 * Register Blocks 
 * @package GutSliderBlocks
 */

 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
 
 if( ! class_exists( 'GutSlider_Register_Blocks' ) ) {

    class GutSlider_Register_Blocks {

        /**
         * Constructor
         * return void 
         */
        public function __construct() {
            add_action( 'init', [ $this, 'register_blocks' ] );
        }

        /**
         * Register Blocks
         * return void
         */
        public function register_blocks() {
            $blocksFolder = GUTSLIDER_DIR . '/build/blocks';
        
            if ( ! is_dir( $blocksFolder ) ) {
                return;
            }
        
            $active_blocks = [];
        
            $content_slider     = get_option('gut_fixed_content_slider', true);
            $any_content_slider = get_option('gut_any_content_slider', true);
        
            $contents = scandir( $blocksFolder );
            
            foreach ( $contents as $item ) {
                if ( in_array( $item, ['.', '..'] ) ) {
                    continue;
                }
        
                $itemPath = $blocksFolder . DIRECTORY_SEPARATOR . $item;
        
                if ( is_dir( $itemPath ) ) {
                    if ( ( ! $content_slider && $item === 'content-slider' ) || ( ! $any_content_slider && $item === 'any-content' ) ) {
                        continue;
                    }
        
                    $active_blocks[] = $item;
                }
            }
        
            if ( ! empty( $active_blocks ) ) {
                foreach ( $active_blocks as $block ) {
                    register_block_type(GUTSLIDER_DIR . '/build/blocks/' . $block);
                }
            }
        }        
    }

 }

    new GutSlider_Register_Blocks();    // Initialize the class
```
