PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.0.0
ShopBuilder – WooCommerce Builder For Elementor v3.0.0
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
← All changes | app/Controllers/AssetsController.php +165 -88 2.2.13.0.0 View file →
@@ -1,11 +1,16 @@
1 1 <?php
2 +/**
3 + * Assets Controller Class
4 + *
5 + * @package RadiusTheme\SB
6 + */
2 7
3 8 namespace RadiusTheme\SB\Controllers;
4 9
5 -use RadiusTheme\SB\Helpers\BuilderFns;
6 10 use RadiusTheme\SB\Helpers\Fns;
7 11 use RadiusTheme\SB\Models\Settings;
12 +use RadiusTheme\SB\Helpers\BuilderFns;
8 13 use RadiusTheme\SB\Traits\SingletonTrait;
9 14
10 15 // Do not allow directly accessing this file.
11 16 if ( ! defined( 'ABSPATH' ) ) {
@@ -11,8 +16,11 @@
11 16 if ( ! defined( 'ABSPATH' ) ) {
12 17 exit( 'This script cannot be accessed directly.' );
13 18 }
14 19
20 +/**
21 + * Assets Controller Class
22 + */
15 23 class AssetsController {
16 24
17 25 use SingletonTrait;
18 26
@@ -44,13 +52,21 @@
44 52 */
45 53 private $scripts = [];
46 54
47 55 /**
56 + * Cached bundled assets.
57 + *
58 + * @var array|null
59 + */
60 + private $cached_bundled_assets = null;
61 +
62 + /**
48 63 * Class Constructor
49 64 */
50 65 public function __construct() {
51 66 $this->version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : RTSB_VERSION;
52 67
68 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
53 69 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
54 70 self::$ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
55 71 } else {
56 72 self::$ajaxurl = admin_url( 'admin-ajax.php' );
@@ -64,9 +80,9 @@
64 80
65 81 /**
66 82 * Public scripts.
67 83 */
68 - add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_public_scripts' ], 15 );
84 + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_public_scripts' ], 25 );
69 85 /**
70 86 * General scripts.
71 87 */
72 88 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_general_public_scripts' ], 30 );
@@ -86,14 +102,20 @@
86 102 *
87 103 * @return object
88 104 */
89 105 private function get_public_styles() {
90 - $rtl_suffix = is_rtl() ? '-rtl' : '';
106 + $rtl_suffix = is_rtl() ? '-rtl' : '';
107 + $rtl_dir = is_rtl() ? trailingslashit( 'rtl' ) : trailingslashit( 'css' );
108 +
91 109 $this->styles[] = [
110 + 'handle' => 'rtsb-odometer',
111 + 'src' => rtsb()->get_assets_uri( 'vendor/odometer/css/odometer.min.css' ),
112 + ];
113 +
114 + $this->styles[] = [
92 115 'handle' => 'rtsb-fonts',
93 116 'src' => rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ),
94 117 ];
95 -
96 118 if ( rtsb()->has_pro() ) {
97 119 $this->styles[] = [
98 120 'handle' => 'rtsb-noui-slider',
99 121 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.css' ),
@@ -99,18 +121,25 @@
99 121 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.css' ),
100 122 ];
101 123 }
102 124
103 - $this->styles[] = [
104 - 'handle' => 'rtsb-frontend',
105 - 'src' => rtsb()->get_assets_uri( 'css/frontend/frontend' . $rtl_suffix . '.css' ),
106 - ];
125 + $pro_version = defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : '0';
126 + $addon_condition = version_compare( $pro_version, '1.9.0', '<' );
107 127
108 - $this->styles[] = [
109 - 'handle' => 'swiper',
110 - 'src' => rtsb()->get_assets_uri( 'vendor/swiper/css/swiper-bundle.min.css' ),
111 - ];
112 -
128 + if ( ! rtsb()->has_pro() && Fns::is_optimization_enabled() ) {
129 + $this->styles[] = AssetRegistry::instance()->load_optimized_assets();
130 + } else {
131 + if ( $addon_condition ) {
132 + $this->styles[] = [
133 + 'handle' => 'rtsb-general-addons',
134 + 'src' => rtsb()->get_assets_uri( $rtl_dir . 'frontend/general-addons' . $rtl_suffix . '.css' ),
135 + ];
136 + }
137 + $this->styles[] = [
138 + 'handle' => 'rtsb-frontend',
139 + 'src' => rtsb()->get_assets_uri( $rtl_dir . 'frontend/frontend' . $rtl_suffix . '.css' ),
140 + ];
141 + }
113 142 if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
114 143 $this->styles[] = [
115 144 'handle' => 'photoswipe',
116 145 'src' => plugins_url( 'assets/css/photoswipe/photoswipe.min.css', WC_PLUGIN_FILE ),
@@ -136,40 +165,26 @@
136 165 *
137 166 * @return object
138 167 */
139 168 private function get_public_scripts() {
140 -
141 - $default_swiper_path = rtsb()->get_assets_uri( 'vendor/swiper/js/swiper-bundle.min.js' );
142 -
143 - if ( defined( 'ELEMENTOR_ASSETS_PATH' ) ) {
144 - $is_swiper8_enable = get_option( 'elementor_experiment-e_swiper_latest' );
145 -
146 - if ( 'active' === $is_swiper8_enable || 'default' === $is_swiper8_enable ) {
147 - $el_swiper_path = 'lib/swiper/v8/swiper.min.js';
148 - } else {
149 - $el_swiper_path = 'lib/swiper/swiper.min.js';
150 - }
151 -
152 - $elementor_swiper_path = ELEMENTOR_ASSETS_PATH . $el_swiper_path;
153 -
154 - if ( file_exists( $elementor_swiper_path ) ) {
155 - $default_swiper_path = ELEMENTOR_ASSETS_URL . $el_swiper_path;
156 - }
157 - }
158 -
159 169 $this->scripts[] = [
160 170 'handle' => 'swiper',
161 - 'src' => esc_url( $default_swiper_path ),
171 + 'src' => esc_url( $this->get_swiper_url() ),
162 172 'deps' => [ 'jquery' ],
163 173 'footer' => true,
164 174 ];
165 -
166 175 $this->scripts[] = [
167 - 'handle' => 'rtsb-imagesloaded',
168 - 'src' => rtsb()->get_assets_uri( 'vendor/isotope/imagesloaded.pkgd.min.js' ),
176 + 'handle' => 'rtsb-waypoints',
177 + 'src' => rtsb()->get_assets_uri( 'vendor/waypoints/js/jquery.waypoints.min.js' ),
169 178 'deps' => [ 'jquery' ],
170 179 'footer' => true,
171 180 ];
181 + $this->scripts[] = [
182 + 'handle' => 'rtsb-odometer',
183 + 'src' => rtsb()->get_assets_uri( 'vendor/odometer/js/odometer.min.js' ),
184 + 'deps' => [ 'jquery' ],
185 + 'footer' => true,
186 + ];
172 187
173 188 $this->scripts[] = [
174 189 'handle' => 'rtsb-tipsy',
175 190 'src' => rtsb()->get_assets_uri( 'vendor/tipsy/tipsy.min.js' ),
@@ -228,16 +243,34 @@
228 243 'src' => rtsbpro()->get_assets_uri( 'vendors/sticky-sidebar/sticky-sidebar.min.js' ),
229 244 'deps' => [ 'jquery' ],
230 245 'footer' => true,
231 246 ];
247 +
248 + $this->scripts[] = [
249 + 'handle' => 'rtsb-popper',
250 + 'src' => rtsbpro()->get_assets_uri( 'vendors/tippy/popper.min.js' ),
251 + 'deps' => [ 'jquery' ],
252 + 'footer' => true,
253 + ];
254 +
255 + $this->scripts[] = [
256 + 'handle' => 'rtsb-tippy',
257 + 'src' => rtsbpro()->get_assets_uri( 'vendors/tippy/tippy.min.js' ),
258 + 'deps' => [ 'jquery', 'rtsb-popper' ],
259 + 'footer' => true,
260 + ];
232 261 }
233 262
234 - $this->scripts[] = [
235 - 'handle' => 'rtsb-public',
236 - 'src' => rtsb()->get_assets_uri( 'js/frontend/frontend.js' ),
237 - 'deps' => [ 'jquery', 'rtsb-imagesloaded', 'swiper' ],
238 - 'footer' => true,
239 - ];
263 + if ( ! rtsb()->has_pro() && Fns::is_optimization_enabled() ) {
264 + $this->scripts[] = AssetRegistry::instance()->load_optimized_assets( 'js' );
265 + } else {
266 + $this->scripts[] = [
267 + 'handle' => 'rtsb-public',
268 + 'src' => rtsb()->get_assets_uri( 'js/frontend/frontend.js' ),
269 + 'deps' => [ 'jquery', 'imagesloaded', 'swiper' ],
270 + 'footer' => true,
271 + ];
272 + }
240 273
241 274 return $this;
242 275 }
243 276
@@ -247,8 +280,10 @@
247 280 * @return void
248 281 */
249 282 public function register_public_scripts() {
250 283 $this->get_public_assets();
284 + $this->styles = array_filter( $this->styles );
285 + $this->scripts = array_filter( $this->scripts );
251 286
252 287 // Register public styles.
253 288 foreach ( $this->styles as $style ) {
254 289 wp_register_style( $style['handle'], $style['src'], '', $this->version );
@@ -269,8 +304,9 @@
269 304 /**
270 305 * Register scripts.
271 306 */
272 307 $this->register_public_scripts();
308 +
273 309 /**
274 310 * Enqueue scripts.
275 311 */
276 312 if ( BuilderFns::is_builder_preview() && 'elementor' === Fns::page_edit_with( get_the_ID() ) ) {
@@ -276,9 +312,8 @@
276 312 if ( BuilderFns::is_builder_preview() && 'elementor' === Fns::page_edit_with( get_the_ID() ) ) {
277 313 /**
278 314 * Styles.
279 315 */
280 - wp_enqueue_style( 'swiper' );
281 316 wp_enqueue_style( 'photoswipe' );
282 317 wp_enqueue_style( 'photoswipe-default-skin' );
283 318 wp_enqueue_style( 'elementor-editor-style-fix' );
284 319 wp_enqueue_style( 'woocommerce-general' );
@@ -285,27 +320,31 @@
285 320
286 321 /**
287 322 * Scripts.
288 323 */
324 + $handle = Fns::optimized_handle( 'rtsb-public' );
325 +
289 326 wp_enqueue_script( 'flexslider' );
290 327 wp_enqueue_script( 'wc-single-product' );
291 - wp_dequeue_script( 'rtsb-public' );
328 + wp_dequeue_script( $handle );
292 329 wp_enqueue_script( 'swiper' );
293 - wp_enqueue_script( 'rtsb-public' );
330 +
331 + if ( Fns::is_optimization_enabled() ) {
332 + Fns::enqueue_optimized_assets();
333 + } else {
334 + wp_enqueue_script( $handle );
335 + }
294 336 }
295 337
296 - /**
297 - * Styles.
298 - */
299 - wp_enqueue_style( 'rtsb-fonts' );
300 - wp_enqueue_style( 'rtsb-frontend' );
338 + wp_enqueue_script( 'rtsb-tipsy' );
301 339
302 - /**
303 - * Scripts.
304 - */
305 - wp_enqueue_script( 'rtsb-imagesloaded' );
306 - wp_enqueue_script( 'rtsb-tipsy' );
307 - wp_enqueue_script( 'rtsb-public' );
340 + if ( Fns::is_optimization_enabled() ) {
341 + Fns::enqueue_optimized_assets();
342 + } else {
343 + wp_enqueue_style( 'rtsb-fonts' );
344 + wp_enqueue_style( 'rtsb-frontend' );
345 + wp_enqueue_script( 'rtsb-public' );
346 + }
308 347
309 348 /**
310 349 * Localize script.
311 350 */
@@ -318,24 +357,27 @@
318 357 * @static
319 358 * @return void
320 359 */
321 360 public static function localizeData() {
361 + $handle = Fns::optimized_handle( 'rtsb-public' );
362 +
322 363 wp_localize_script(
323 - 'rtsb-public',
364 + $handle,
324 365 'rtsbPublicParams',
325 366 [
326 - 'ajaxUrl' => esc_url( self::$ajaxurl ),
327 - 'homeurl' => home_url(),
328 - 'wcCartUrl' => wc_get_cart_url(),
329 - 'addedToCartText' => esc_html__( 'Product Added', 'shopbuilder' ),
330 - 'singleCartToastrText' => esc_html__( 'Successfully Added', 'shopbuilder' ),
331 - 'singleCartBtnText' => apply_filters( 'rtsb/global/single_add_to_cart_success', esc_html__( 'Added to Cart', 'shopbuilder' ) ),
332 - 'browseCartText' => esc_html__( 'Browse Cart', 'shopbuilder' ),
333 - 'noProductsText' => apply_filters( 'rtsb/global/no_products_text', esc_html__( 'No more products to load', 'shopbuilder' ) ),
334 - 'notice' => [
367 + 'ajaxUrl' => esc_url( self::$ajaxurl ),
368 + 'homeurl' => home_url(),
369 + 'wcCartUrl' => wc_get_cart_url(),
370 + 'addedToCartText' => esc_html__( 'Product Added', 'shopbuilder' ),
371 + 'singleCartToastrText' => esc_html__( 'Successfully Added', 'shopbuilder' ),
372 + 'singleCartBtnText' => apply_filters( 'rtsb/global/single_add_to_cart_success', esc_html__( 'Added to Cart', 'shopbuilder' ) ),
373 + 'browseCartText' => esc_html__( 'Browse Cart', 'shopbuilder' ),
374 + 'noProductsText' => apply_filters( 'rtsb/global/no_products_text', esc_html__( 'No more products to load', 'shopbuilder' ) ),
375 + 'isOptimizationEnabled' => Fns::is_optimization_enabled(),
376 + 'notice' => [
335 377 'position' => Fns::get_option( 'general', 'notification', 'notification_position', 'center-center' ),
336 378 ],
337 - rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
379 + rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
338 380 ]
339 381 );
340 382 }
341 383
@@ -372,18 +414,17 @@
372 414
373 415 /**
374 416 * Enqueues admin scripts.
375 417 *
376 - * @param string $hook Hooks.
377 - *
378 418 * @return void
379 419 */
380 - public function enqueue_backend_scripts( $hook ) {
420 + public function enqueue_backend_scripts() {
381 421 ob_start(); ?>
382 422 #adminmenu .toplevel_page_rtsb .wp-menu-image img {
383 423 width: auto;
384 424 height: 22px;
385 425 padding: 4px 0;
426 + box-sizing: content-box;
386 427 }
387 428 .post-type-rtsb_builder li#wp-admin-bar-WPML_ALS_all,
388 429 .post-type-rtsb_builder li.language_all{
389 430 display: none;
@@ -392,12 +433,22 @@
392 433 <?php
393 434 $admin_global_style = ob_get_clean();
394 435 // Speed Optimization.
395 436 wp_add_inline_style( 'admin-menu', $admin_global_style );
396 - // wp_enqueue_style( 'rtsb-admin-global' );
397 437
398 438 global $pagenow;
399 439
440 + $whitelisted_pages = [ 'rtsb-settings', 'rtsb-get-help', 'rtsb-themes' ];
441 + $current_page = ! empty( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
442 +
443 + if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && in_array( $current_page, $whitelisted_pages, true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
444 + /**
445 + * Styles.
446 + */
447 + wp_enqueue_style( 'rtsb-admin-app' );
448 + wp_enqueue_style( 'rtsb-fonts' );
449 + }
450 +
400 451 if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && 'rtsb-settings' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
401 452 // Elementor Console Error Fixed For "rtsb-settings" Page.
402 453 wp_dequeue_script( 'elementor-admin-top-bar' );
403 454 wp_dequeue_script( 'elementor-common' );
@@ -405,8 +456,9 @@
405 456 wp_dequeue_script( 'elementor-web-cli' );
406 457 wp_dequeue_script( 'elementor-import-export-admin' );
407 458 wp_dequeue_script( 'elementor-app-loader' );
408 459 wp_dequeue_script( 'elementor-admin-modules' );
460 + wp_dequeue_script( 'elementor-ai-media-library' );
409 461 wp_dequeue_script( 'elementor-admin' );
410 462
411 463 wp_dequeue_style( 'elementor-admin-top-bar' );
412 464 wp_dequeue_style( 'elementor-admin' );
@@ -413,16 +465,11 @@
413 465 wp_dequeue_style( 'e-theme-ui-light' );
414 466 wp_dequeue_style( 'elementor-common' );
415 467
416 468 /**
417 - * Styles.
418 - */
419 - wp_enqueue_style( 'rtsb-admin-app' );
420 - wp_enqueue_style( 'rtsb-fonts' );
421 -
422 - /**
423 469 * Scripts.
424 470 */
471 + wp_enqueue_media();
425 472 wp_enqueue_script( 'updates' );
426 473 wp_enqueue_script( 'rtsb-admin-app' );
427 474 wp_localize_script(
428 475 'rtsb-admin-app',
@@ -427,18 +474,23 @@
427 474 wp_localize_script(
428 475 'rtsb-admin-app',
429 476 'rtsbParams',
430 477 [
431 - 'ajaxurl' => esc_url( self::$ajaxurl ),
432 - 'homeurl' => home_url(),
433 - 'adminLogo' => rtsb()->get_assets_uri( 'images/icon/ShopBuilder-Logo.svg' ),
434 - 'restApiUrl' => esc_url_raw( rest_url() ),
435 - 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
436 - 'nonce' => wp_create_nonce( rtsb()->nonceText ),
437 - 'sections' => Settings::instance()->get_sections(),
438 - 'pages' => Fns::get_pages(),
439 - 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no',
440 - 'updateRates' => esc_html__( 'Update All Rates', 'shopbuilder' ),
478 + 'ajaxurl' => esc_url( self::$ajaxurl ),
479 + 'homeurl' => home_url(),
480 + 'adminLogo' => rtsb()->get_assets_uri( 'images/icon/ShopBuilder-Logo.svg' ),
481 + 'restApiUrl' => esc_url_raw( rest_url() ),
482 + 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
483 + 'nonce' => wp_create_nonce( rtsb()->nonceText ),
484 + 'pages' => Fns::get_pages(),
485 + 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no',
486 + 'proVersion' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : '0',
487 + 'updateRates' => esc_html__( 'Update All Rates', 'shopbuilder' ),
488 + 'sections' => Settings::instance()->get_sections(),
489 + 'userRoles' => Fns::get_all_user_roles(),
490 + 'hasElementor' => defined( 'ELEMENTOR_VERSION' ),
491 + 'loadElementor' => Fns::should_load_elementor_scripts(),
492 + 'isOptimizationEnabled' => Fns::is_optimization_enabled(),
441 493 ]
442 494 );
443 495 } else {
444 496 $current_screen = get_current_screen();
@@ -499,8 +551,33 @@
499 551 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success a{color:{$notification_button_color}}";
500 552 }
501 553
502 554 if ( ! empty( $dynamic_css ) ) {
503 - wp_add_inline_style( 'rtsb-frontend', $dynamic_css );
555 + wp_add_inline_style( Fns::optimized_handle( 'rtsb-frontend' ), $dynamic_css );
504 556 }
557 + }
558 +
559 + /**
560 + * Get the appropriate Swiper JS file URL.
561 + *
562 + * @return string
563 + */
564 + private function get_swiper_url() {
565 + $default_swiper_url = rtsb()->get_assets_uri( 'vendor/swiper/js/swiper-bundle.min.js' );
566 +
567 + if ( defined( 'ELEMENTOR_ASSETS_PATH' ) && defined( 'ELEMENTOR_ASSETS_URL' ) ) {
568 + $experiment = get_option( 'elementor_experiment-e_swiper_latest' );
569 +
570 + $el_relative_path = ( 'active' === $experiment || 'default' === $experiment )
571 + ? 'lib/swiper/v8/swiper.min.js'
572 + : 'lib/swiper/swiper.min.js';
573 +
574 + $el_full_path = ELEMENTOR_ASSETS_PATH . $el_relative_path;
575 +
576 + if ( file_exists( $el_full_path ) ) {
577 + return ELEMENTOR_ASSETS_URL . $el_relative_path;
578 + }
579 + }
580 +
581 + return $default_swiper_url;
505 582 }
506 583 }