PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.5.3
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.5.3
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.3, at includes/classes/class-enqueue-assets.php

138 lines 5.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 if( file_exists( trailingslashit( GUTSLIDER_DIR_PATH ) . './build/global/global.asset.php' ) ){
28 $dependency_file = include_once trailingslashit( GUTSLIDER_DIR_PATH ) . './build/global/global.asset.php';
29 }
30
31 if( is_array( $dependency_file ) && ! empty( $dependency_file ) ) {
32 wp_enqueue_script(
33 'gutslider-blocks-global-script',
34 trailingslashit( GUTSLIDER_URL ) . './build/global/global.js',
35 isset( $dependency_file['dependencies'] ) ? $dependency_file['dependencies'] : [],
36 isset( $dependency_file['version'] ) ? $dependency_file['version'] : GUTSLIDER_VERSION,
37 true
38 );
39 }
40
41 wp_enqueue_style(
42 'gutslider-blocks-global-style',
43 trailingslashit( GUTSLIDER_URL ) . './build/global/global.css',
44 [],
45 GUTSLIDER_VERSION
46 );
47
48 // modules
49 if( file_exists( trailingslashit( GUTSLIDER_DIR_PATH ) . './build/modules/modules.asset.php' ) ) {
50 $modules_dependency_file = include_once trailingslashit( GUTSLIDER_DIR_PATH ) . './build/modules/modules.asset.php';
51 }
52
53 if( is_array( $modules_dependency_file ) && ! empty( $modules_dependency_file ) ) {
54 wp_enqueue_script(
55 'gutslider-blocks-modules-script',
56 trailingslashit( GUTSLIDER_URL ) . './build/modules/modules.js',
57 isset( $modules_dependency_file['dependencies'] ) ? $modules_dependency_file['dependencies'] : [],
58 isset( $modules_dependency_file['version'] ) ? $modules_dependency_file['version'] : GUTSLIDER_VERSION,
59 false
60 );
61 }
62
63 // wp localize script
64 wp_localize_script(
65 'gutslider-blocks-modules-script',
66 'gutslider_preview',
67 [
68 'fixed_content' => trailingslashit( GUTSLIDER_URL ) . 'assets/images/content-slider.svg',
69 'any_content' => trailingslashit( GUTSLIDER_URL ) . 'assets/images/any-content.svg',
70 'photo_carousel' => trailingslashit( GUTSLIDER_URL ) . 'assets/images/photo-carousel.svg',
71 'testimonial_slider' => trailingslashit( GUTSLIDER_URL ) . 'assets/images/testimonial-slider.svg',
72 'post_slider' => trailingslashit( GUTSLIDER_URL ) . 'assets/images/post-slider.svg',
73 ]
74 );
75 }
76
77 /**
78 * Enqueue Block Assets [ Editor + Frontend ]
79 * return void
80 */
81 public function enqueue_assets() {
82
83 if( is_admin() ) {
84 // swiper style
85 wp_enqueue_style(
86 'swiper-style',
87 trailingslashit( GUTSLIDER_URL ) . 'assets/css/swiper-bundle.min.css',
88 [],
89 GUTSLIDER_VERSION
90 );
91
92 // swiper script
93 wp_enqueue_script(
94 'swiper-script',
95 trailingslashit( GUTSLIDER_URL ) . 'assets/js/swiper-bundle.min.js',
96 [],
97 GUTSLIDER_VERSION,
98 true
99 );
100 }
101
102 // enqueue frontend scripts
103 $swiper_scripts = get_option( 'swiper_scripts', true );
104 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' ) )) {
105 // swiper style
106 wp_enqueue_style(
107 'swiper-style',
108 trailingslashit( GUTSLIDER_URL ) . 'assets/css/swiper-bundle.min.css',
109 [],
110 GUTSLIDER_VERSION
111 );
112
113 // swiper script
114 wp_enqueue_script(
115 'swiper-script',
116 trailingslashit( GUTSLIDER_URL ) . 'assets/js/swiper-bundle.min.js',
117 [],
118 GUTSLIDER_VERSION,
119 true
120 );
121 }
122 if( ! is_admin() && ( has_block( 'gutsliders/photo-carousel' ) )) {
123 // lightbox
124 wp_enqueue_script(
125 'gutslider-fslightbox',
126 trailingslashit( GUTSLIDER_URL ) . 'assets/js/fslightbox.js',
127 [],
128 GUTSLIDER_VERSION,
129 true
130 );
131 }
132 }
133
134 }
135
136 }
137
138 new GutSlider_Assets(); // Initialize the class