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

GutSlider – All in One Slider and Carousel Blocks for Gutenberg, version 2.1.0. 50 lines.

- Page: https://pluginprobe.com/plugins/slider-blocks/2.1.0/code/includes/classes/class-register-blocks.php
- Raw: https://pluginprobe.com/plugins/slider-blocks/2.1.0/raw/includes/classes/class-register-blocks.php
- Modified: 2023-09-30T03:38:58+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.1.0/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 ) ) {

                $contents = scandir( $blocksFolder );

                $blocks = array_filter( $contents, function( $item ) use ( $blocksFolder ) {
                    $itemPath = $blocksFolder . DIRECTORY_SEPARATOR . $item;
                    return is_dir( $itemPath ) && !in_array( $item, ['.', '..'] );
                });
            
                if( is_array( $blocks ) && ! empty( $blocks ) ) {
                    foreach ( $blocks as $block ) {
                        register_block_type( GUTSLIDER_DIR . '/build/blocks/' . $block  );
                    }
                }
            } 
        }

    }

 }

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