PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.1
Easy Elements for Elementor – Addons & Website Templates v1.3.1
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / includes / Utils / Enqueue.php

Enqueue.php in Easy Elements for Elementor – Addons & Website Templates 1.3.1, at includes/Utils/Enqueue.php

337 lines 12.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Utils;
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 class Enqueue {
6
7 private static $instance = null;
8 const VERSION = EASYELEMENTS_VER;
9 public static function get_instance() {
10 if ( ! self::$instance ) self::$instance = new self();
11 return self::$instance;
12 }
13
14 private function __construct() {
15 // Assets
16 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_frontend_assets' ], 99 );
17 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_styles' ] );
18 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] );
19
20 add_filter( 'script_loader_tag', [ $this, 'easyel_add_defer_attribute_free' ], 10, 2 );
21
22 add_action( 'wp_enqueue_scripts', [ $this, 'easyel_register_free_all_widget_assets'] );
23 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'easyel_register_free_all_widget_assets'] );
24
25 }
26
27
28 public function enqueue_frontend_assets() {
29 $dir = EASYELEMENTS_DIR_URL;
30 if ( is_admin() ) return;
31 if ( ! class_exists( 'Elementor\Plugin' ) ) return;
32 wp_enqueue_style( 'swiper', ELEMENTOR_ASSETS_URL . 'lib/swiper/css/swiper-bundle.min.css', [], '8.0.7' );
33 wp_enqueue_style( 'easy-hfe-elementor', EASYELEMENTS_ASSETS_URL . 'header-footer/css/easy-hfe-elementor.css', [], self::VERSION );
34
35 wp_enqueue_style( 'eel-elements-plugins', $dir . 'assets/css/plugins.min.css', [], self::VERSION );
36 wp_enqueue_script( 'swiper', ELEMENTOR_ASSETS_URL . 'lib/swiper/swiper-bundle.min.js', [ 'jquery' ], '8.0.7', true );
37 wp_enqueue_script( 'jarallax', $dir . 'assets/js/jarallax.js', [ 'jquery' ], '2.2.1', true );
38 wp_enqueue_script( 'eel-custom-js', $dir . 'assets/js/custom.js', [ 'jquery' ], self::VERSION, true );
39 wp_enqueue_script( 'easy-wrapper-link', $dir . 'assets/js/easy-wrapper-link.js', [ 'jquery' ], self::VERSION, true );
40 }
41
42
43 public function enqueue_admin_styles() {
44 global $pagenow;
45 $screen = get_current_screen();
46 $dir = EASYELEMENTS_DIR_URL;
47 wp_enqueue_style( 'e-e-elements-admin', $dir . 'assets/css/admin/admin.min.css', [], self::VERSION );
48 wp_enqueue_style( 'e-e-easy-custom-icons', $dir . 'includes/Admin/icons/css/easy-icons.css', [], self::VERSION );
49 wp_enqueue_style('e-e-admin-fonts-inter','https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap',false, self::VERSION );
50
51 if ( ( 'ee-elementor-hf' == $screen->id && ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) ) || ( 'edit.php' == $pagenow && 'edit-ee-elementor-hf' == $screen->id ) ) {
52 wp_enqueue_script( 'easy-ehf-admin-script', $dir . 'assets/header-footer/js/ee-ehf-admin.js', [ 'jquery', 'updates' ], self::VERSION, true );
53
54 }
55 }
56
57 public function enqueue_editor_scripts() {
58 wp_enqueue_style( 'eel-elements-editor', EASYELEMENTS_DIR_URL . 'assets/css/editor.min.css', [], self::VERSION );
59 wp_enqueue_style( 'e-e-easy-custom-icons', EASYELEMENTS_DIR_URL . 'includes/Admin/icons/css/easy-icons.css', [], self::VERSION );
60 }
61
62
63
64 /**
65 * ------------------------------------------------------------
66 * Add defer attribute
67 * ------------------------------------------------------------
68 */
69 function easyel_add_defer_attribute_free( $tag, $handle ) {
70
71 $defer_handles = [
72 'swiper',
73 'jarallax',
74 'eel-custom-js',
75 'easy-wrapper-link',
76 'eel-countdown-script',
77 'eel-counter-script',
78 'eel-faq-accordion-script',
79 'eel-gallery-script',
80 'eel-login-register-script',
81 'eel-navigation-menu-script',
82 'eel-offcanvas-script',
83 'eel-scroll-to-top-script',
84 'eel-search-script',
85 'eel-tab-script',
86 'eel-table-script',
87 'eel-team-grid-script',
88 'eel-testimonials-script',
89 ];
90
91 if ( in_array( $handle, $defer_handles, true ) ) {
92 return str_replace( ' src', ' defer src', $tag );
93 }
94
95 return $tag;
96 }
97
98 public function easyel_register_free_all_widget_assets() {
99
100 $widgets_assets = $this->easyel_enqueue_widget_assets();
101
102 $single_archive_widget = array(
103 'eel-featured-image',
104 'eel-post-content',
105 'eel-excerpt',
106 "eel-post-author-info",
107 'eel-post-comments',
108 'eel-post-meta',
109 'eel-post-pagination',
110 'eel-post-tags',
111 'eel-post-title',
112 "eel-breadcrumb",
113 "eel-navigation-menu",
114 "eel-site-logo",
115 );
116
117 foreach ( $widgets_assets as $widget => $assets ) {
118
119 /**
120 * CSS register
121 */
122 if ( ! empty( $assets['css'] ) ) {
123 foreach ( $assets['css'] as $css ) {
124
125 $handle = $widget;
126 $path = EASYELEMENTS_DIR_PATH . $css;
127 $url = EASYELEMENTS_DIR_URL . $css;
128
129 if ( ! file_exists( $path ) ) {
130 continue;
131 }
132
133 $version = filemtime( $path );
134
135 if ( is_singular( 'post' ) && in_array( $handle, $single_archive_widget, true ) ) {
136
137 wp_enqueue_style(
138 $handle,
139 $url,
140 [],
141 $version
142 );
143
144 } else {
145
146 wp_register_style(
147 $handle,
148 $url,
149 [],
150 $version
151 );
152 }
153 }
154 }
155
156 /**
157 * JS register
158 */
159 if ( ! empty( $assets['js'] ) ) {
160 foreach ( $assets['js'] as $js ) {
161
162 $handle = $widget;
163 $path = EASYELEMENTS_DIR_PATH . $js;
164
165 if ( file_exists( $path ) ) {
166 wp_register_script(
167 $handle,
168 EASYELEMENTS_DIR_URL . $js,
169 [ 'jquery' ],
170 filemtime( $path ),
171 true
172 );
173 }
174 }
175 }
176 }
177 }
178
179 function easyel_enqueue_widget_assets() {
180 if ( ! class_exists( '\Elementor\Plugin' ) ) return;
181
182 $widgets_assets = [
183 'eel-archive-post' => [
184 'css' => ['widgets/archive-post/css/archive-post.min.css'],
185 ],
186 'eel-blog-grid' => [
187 'css' => ['widgets/blog-grid/css/blog-grid.min.css'],
188 ],
189 'eel-breadcrumb' => [
190 'css' => ['widgets/breadcrumb/css/breadcrumb.min.css'],
191 ],
192 'eel-button' => [
193 'css' => ['widgets/button/css/button.min.css'],
194 ],
195 'eel-cf7' => [
196 'css' => ['widgets/cf7/css/cf7.min.css'],
197 ],
198 'eel-clients-logo-grid' => [
199 'css' => ['widgets/clients-logo-grid/css/clients-logo.min.css'],
200 ],
201 'eel-contact-box' => [
202 'css' => ['widgets/contact-box/css/contact-box.min.css'],
203 ],
204 'eel-countdown' => [
205 'css' => ['widgets/countdown/css/countdown.min.css'],
206 'js' => ['widgets/countdown/js/countdown.js'],
207 ],
208 'eel-counter' => [
209 'css' => ['widgets/counter/css/counter.min.css'],
210 'js' => ['widgets/counter/js/counter.js'],
211 ],
212 'eel-domain-search' => [
213 'css' => ['widgets/domain-search/css/domain-search.min.css'],
214 ],
215 'eel-excerpt' => [
216 'css' => ['widgets/excerpt/css/excerpt.min.css'],
217 ],
218 'eel-faq-accordion' => [
219 'css' => ['widgets/faq/css/faq.min.css'],
220 'js' => ['widgets/faq/js/faq.js'],
221 ],
222 'eel-feature-list' => [
223 'css' => ['widgets/feature-list/css/feature-list.min.css'],
224 ],
225 'eel-featured-image' => [
226 'css' => ['widgets/featured-image/css/featured-image.min.css'],
227 ],
228 'eel-gallery' => [
229 'css' => ['widgets/gallery/css/gallery.min.css'],
230 'js' => ['widgets/gallery/js/simple-gallery.js'],
231 ],
232 'eel-heading' => [
233 'css' => ['widgets/heading/css/heading.min.css'],
234 ],
235 'eel-icon-box' => [
236 'css' => ['widgets/icon-box/css/icon-box.min.css'],
237 ],
238 'eel-login-register' => [
239 'css' => ['widgets/login-register/css/login-register.min.css'],
240 'js' => ['widgets/login-register/js/login-register.js'],
241 ],
242 'eel-navigation-menu' => [
243 'css' => ['widgets/navigation-menu/css/navigation-menu.min.css'],
244 'js' => [
245 'widgets/navigation-menu/js/navigation-menu.min.js',
246 'widgets/navigation-menu/js/eel-sticky-header.js',
247 ],
248 ],
249 'eel-offcanvas' => [
250 'css' => ['widgets/offcanvas/css/offcanvas.min.css'],
251 'js' => ['widgets/offcanvas/js/offcanvas.js'],
252 ],
253 'eel-page-title' => [
254 'css' => ['widgets/page-title/css/page-title.min.css'],
255 ],
256 'eel-post-author-info' => [
257 'css' => ['widgets/post-author/css/post-author.min.css'],
258 ],
259 'eel-post-comments' => [
260 'css' => ['widgets/post-comments/css/post-comments.min.css'],
261 ],
262 'eel-post-content' => [
263 'css' => ['widgets/post-content/css/post-content.min.css'],
264 ],
265 'eel-post-meta' => [
266 'css' => ['widgets/post-meta/css/post-meta.min.css'],
267 ],
268 'eel-post-pagination' => [
269 'css' => ['widgets/post-pagination/css/post-pagination.min.css'],
270 ],
271 'eel-post-tags' => [
272 'css' => ['widgets/post-tag/css/post-tag.min.css'],
273 ],
274 'eel-post-title' => [
275 'css' => ['widgets/post-title/css/post-title.min.css'],
276 ],
277 'eel-pricing' => [
278 'css' => ['widgets/pricing-table/css/pricing.min.css'],
279 ],
280 'eel-process' => [
281 'css' => ['widgets/process-grid/css/process.min.css'],
282 ],
283 'eel-process-list' => [
284 'css' => ['widgets/process-list/css/process-list.min.css'],
285 ],
286 'easyel-progress-bar' => [
287 'css' => ['widgets/progress/css/progress.min.css'],
288 ],
289 'eel-scroll-to-top' => [
290 'css' => ['widgets/scroll-to-top/css/scroll.min.css'],
291 'js' => ['widgets/scroll-to-top/js/scroll.js'],
292 ],
293 'eel-search' => [
294 'css' => ['widgets/search/css/search.min.css'],
295 'js' => ['widgets/search/js/search.js'],
296 ],
297 'eel-service-list' => [
298 'css' => ['widgets/service-list/css/service-list.min.css'],
299 ],
300 'eel-site-logo' => [
301 'css' => ['widgets/site-logo/css/logo.min.css'],
302 ],
303 'eel-social-icon' => [
304 'css' => ['widgets/social-icon/css/social.min.css'],
305 ],
306 'eel-social-share' => [
307 'css' => ['widgets/social-share/css/social-share.min.css'],
308 ],
309 'eel-tab' => [
310 'css' => ['widgets/tab/css/tab.min.css'],
311 'js' => ['widgets/tab/js/tab.js'],
312 ],
313 'eel-table' => [
314 'css' => ['widgets/table/css/table.min.css'],
315 'js' => ['widgets/table/js/table.js'],
316 ],
317 'eel-team-grid' => [
318 'css' => ['widgets/team-grid/css/team-grid.min.css'],
319 'js' => ['widgets/team-grid/js/team.js'],
320 ],
321 'eel-testimonials' => [
322 'css' => ['widgets/testimonials-grid/css/testimonials.min.css'],
323 'js' => ['widgets/testimonials-grid/js/testimonial.js'],
324 ],
325 'eel-video-popup' => [
326 'css' => ['widgets/video/css/video.min.css'],
327 ],
328 'eel-single-nav' => [
329 'css' => ['widgets/single-nav/css/single-nav.min.css'],
330 ],
331 ];
332
333 return $widgets_assets;
334
335 }
336
337 }