PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.2.2
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.2.2
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-generate-style.php

class-generate-style.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 2.2.2, at includes/classes/class-generate-style.php

53 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Generate Dynamic Style
4 * @package GutSliderBlocks
5 */
6
7 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
8
9 if( ! class_exists( 'GutSlider_Dynamic_Style' ) ) {
10
11 class GutSlider_Dynamic_Style {
12
13 /**
14 * Constructor
15 * return void
16 */
17 public function __construct() {
18 add_filter( 'render_block', [ $this, 'generate_dynamic_style' ], 10, 2 );
19 }
20
21 function generate_dynamic_style($block_content, $block) {
22 if (isset($block['blockName']) && str_contains($block['blockName'], 'gutsliders/')) {
23
24 do_action( 'gutsliders_render_block', $block );
25
26 if (isset($block['attrs']['blockStyle'])) {
27
28 $style = $block['attrs']['blockStyle'];
29
30 $handle = isset( $block['attrs']['uniqueId'] ) ? $block['attrs']['uniqueId'] : 'slider-blocks';
31
32 if ( is_array( $style ) && !empty( $style ) ) {
33 $style = implode(' ', $style);
34 }
35 // minify style to remove extra space
36 $style = preg_replace( '/\s+/', ' ', $style );
37
38 // register style
39 wp_register_style( $handle, false, [], GUTSLIDER_VERSION, 'all' ); // wp_register_style( $handle, $src, $deps, $ver, $media );
40 wp_enqueue_style( $handle );
41 wp_add_inline_style( $handle, $style );
42
43 }
44
45 }
46 return $block_content;
47 }
48
49 }
50
51 }
52
53 new GutSlider_Dynamic_Style(); // Initialize the class