PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.6.1
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.6.1
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-frontend-scripts.php

class-frontend-scripts.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 2.6.1, at includes/classes/class-frontend-scripts.php

57 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Enqueue Blocks Frontend Scripts
4 * @package GutSliderBlocks
5 */
6
7 if( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
8
9 if( ! class_exists( 'GutSlider_Blocks_Frontend_Scripts' ) ) {
10
11 class GutSlider_Blocks_Frontend_Scripts {
12
13 /**
14 * Constructor
15 * @return void
16 */
17 public function __construct() {
18 // enqueue scripts using wp_enqueue_scripts hook
19 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_assets' ], 9999 );
20 }
21
22 /**
23 * Register blocks
24 * @return void
25 */
26 public function enqueue_assets() {
27
28 $blocksFolder = trailingslashit( GUTSLIDER_DIR ) . '/build/blocks';
29
30 if ( is_dir( $blocksFolder ) ) {
31
32 $contents = scandir( $blocksFolder );
33
34 $blocks = array_filter( $contents, function( $item ) use ( $blocksFolder ) {
35
36 $frontendScripts = $blocksFolder . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . 'frontend.js';
37 $frontendDependencies = $blocksFolder . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . 'frontend.asset.php';
38
39 if( file_exists( $frontendScripts ) && file_exists( $frontendDependencies ) ) {
40 $frontendDependencies = include_once $frontendDependencies;
41
42 $block_name = 'gutsliders/' . $item;
43
44 if( has_block( $block_name ) ) {
45 wp_enqueue_script( 'gutsliders-' . $item . '-frontend-script', trailingslashit( GUTSLIDER_URL ) . 'build/blocks/' . $item . '/frontend.js', $frontendDependencies['dependencies'], $frontendDependencies['version'], true );
46 }
47 }
48 });
49 }
50
51 }
52
53 }
54
55 }
56
57 new GutSlider_Blocks_Frontend_Scripts(); // Initialize the class