PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.5.4
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.5.4
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-enqueue-assets.php

class-enqueue-assets.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 2.5.4, at includes/classes/class-enqueue-assets.php

160 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Enqueue Assets
4 * @package GutSliderBlocks
5 */
6
7 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
8
9 if( ! class_exists( 'GutSlider_Assets' ) ) {
10
11 class GutSlider_Assets {
12
13 /**
14 * Constructor
15 * return void
16 */
17 public function __construct() {
18 add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_editor_assets' ], 1 );
19 add_action( 'enqueue_block_assets', [ $this, 'enqueue_assets' ] );
20 }
21
22 /**
23 * Enqueue Block Assets [ Editor Only ]
24 * return void
25 */
26 public function enqueue_editor_assets(){
27
28 // enqueue patterns
29 // if( file_exists( trailingslashit( GUTSLIDER_DIR_PATH ) . './build/patterns/patterns.asset.php' ) ) {
30 // $patterns_dependency_file = include_once trailingslashit( GUTSLIDER_DIR_PATH ) . './build/patterns/patterns.asset.php';
31 // }
32
33 // if( is_array( $patterns_dependency_file ) && ! empty( $patterns_dependency_file ) ) {
34 // wp_enqueue_script(
35 // 'gutslider-blocks-patterns-script',
36 // trailingslashit( GUTSLIDER_URL ) . './build/patterns/patterns.js',
37 // isset( $patterns_dependency_file['dependencies'] ) ? $patterns_dependency_file['dependencies'] : [],
38 // isset( $patterns_dependency_file['version'] ) ? $patterns_dependency_file['version'] : GUTSLIDER_VERSION,
39 // true
40 // );
41
42 // wp_enqueue_style(
43 // 'gutslider-blocks-patterns-style',
44 // trailingslashit( GUTSLIDER_URL ) . './build/patterns/style-patterns.css',
45 // [],
46 // GUTSLIDER_VERSION
47 // );
48 // }
49
50 // global
51 if( file_exists( trailingslashit( GUTSLIDER_DIR_PATH ) . './build/global/global.asset.php' ) ){
52 $dependency_file = include_once trailingslashit( GUTSLIDER_DIR_PATH ) . './build/global/global.asset.php';
53 }
54
55 if( is_array( $dependency_file ) && ! empty( $dependency_file ) ) {
56 wp_enqueue_script(
57 'gutslider-blocks-global-script',
58 trailingslashit( GUTSLIDER_URL ) . './build/global/global.js',
59 isset( $dependency_file['dependencies'] ) ? $dependency_file['dependencies'] : [],
60 isset( $dependency_file['version'] ) ? $dependency_file['version'] : GUTSLIDER_VERSION,
61 true
62 );
63 }
64
65 wp_enqueue_style(
66 'gutslider-blocks-global-style',
67 trailingslashit( GUTSLIDER_URL ) . './build/global/global.css',
68 [],
69 GUTSLIDER_VERSION
70 );
71
72 // modules
73 if( file_exists( trailingslashit( GUTSLIDER_DIR_PATH ) . './build/modules/modules.asset.php' ) ) {
74 $modules_dependency_file = include_once trailingslashit( GUTSLIDER_DIR_PATH ) . './build/modules/modules.asset.php';
75 }
76
77 if( is_array( $modules_dependency_file ) && ! empty( $modules_dependency_file ) ) {
78 wp_enqueue_script(
79 'gutslider-blocks-modules-script',
80 trailingslashit( GUTSLIDER_URL ) . './build/modules/modules.js',
81 isset( $modules_dependency_file['dependencies'] ) ? $modules_dependency_file['dependencies'] : [],
82 isset( $modules_dependency_file['version'] ) ? $modules_dependency_file['version'] : GUTSLIDER_VERSION,
83 false
84 );
85 }
86
87 // wp localize script
88 wp_localize_script(
89 'gutslider-blocks-modules-script',
90 'gutslider_preview',
91 [
92 'content' => trailingslashit( GUTSLIDER_URL ) . 'assets/images/content.svg',
93 'photo_carousel' => trailingslashit( GUTSLIDER_URL ) . 'assets/images/photo.svg',
94 'testimonial_slider' => trailingslashit( GUTSLIDER_URL ) . 'assets/images/testimonial.svg',
95 ]
96 );
97 }
98
99 /**
100 * Enqueue Block Assets [ Editor + Frontend ]
101 * return void
102 */
103 public function enqueue_assets() {
104
105 if( is_admin() ) {
106 // swiper style
107 wp_enqueue_style(
108 'swiper-style',
109 trailingslashit( GUTSLIDER_URL ) . 'assets/css/swiper-bundle.min.css',
110 [],
111 GUTSLIDER_VERSION
112 );
113
114 // swiper script
115 wp_enqueue_script(
116 'swiper-script',
117 trailingslashit( GUTSLIDER_URL ) . 'assets/js/swiper-bundle.min.js',
118 [],
119 GUTSLIDER_VERSION,
120 true
121 );
122 }
123
124 // enqueue frontend scripts
125 $swiper_scripts = get_option( 'swiper_scripts', true );
126 if( ! is_admin() && $swiper_scripts && ( has_block( 'gutsliders/content-slider' ) || has_block( 'gutsliders/any-content' ) || has_block( 'gutsliders/testimonial-slider' ) || has_block( 'gutsliders/post-slider' ) || has_block( 'gutsliders/photo-carousel' ) || has_block( 'gutsliders/logo-carousel' ) || has_block( 'gutsliders/contentspro' ) )) {
127 // swiper style
128 wp_enqueue_style(
129 'swiper-style',
130 trailingslashit( GUTSLIDER_URL ) . 'assets/css/swiper-bundle.min.css',
131 [],
132 GUTSLIDER_VERSION
133 );
134
135 // swiper script
136 wp_enqueue_script(
137 'swiper-script',
138 trailingslashit( GUTSLIDER_URL ) . 'assets/js/swiper-bundle.min.js',
139 [],
140 GUTSLIDER_VERSION,
141 true
142 );
143 }
144 if( ! is_admin() && ( has_block( 'gutsliders/photo-carousel' ) )) {
145 // lightbox
146 wp_enqueue_script(
147 'gutslider-fslightbox',
148 trailingslashit( GUTSLIDER_URL ) . 'assets/js/fslightbox.js',
149 [],
150 GUTSLIDER_VERSION,
151 true
152 );
153 }
154 }
155
156 }
157
158 }
159
160 new GutSlider_Assets(); // Initialize the class