| @@ -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,19 +52,27 @@ | ||
| 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' ); |
| 57 | 73 | } |
| 58 | - | |
| 74 | + add_filter( 'rtsb/optimizer/scripts/deps', [ $this, 'extend_shared_dependencies' ], 99 ); | |
| 59 | 75 | /** |
| 60 | 76 | * Admin scripts. |
| 61 | 77 | */ |
| 62 | 78 | add_action( 'admin_enqueue_scripts', [ $this, 'register_backend_assets' ], 1 ); |
| @@ -64,16 +80,28 @@ | ||
| 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 ); |
| 73 | 89 | } |
| 74 | - | |
| 75 | 90 | /** |
| 91 | + * Shared dependencies. | |
| 92 | + * | |
| 93 | + * @param array $deps Dependencies. | |
| 94 | + * | |
| 95 | + * @return array | |
| 96 | + */ | |
| 97 | + public function extend_shared_dependencies( $deps ) { | |
| 98 | + if ( Fns::is_elementor_widget_active( 'products_slider' ) ) { | |
| 99 | + $deps[] = 'swiper'; | |
| 100 | + } | |
| 101 | + return array_unique( $deps ); | |
| 102 | + } | |
| 103 | + /** | |
| 76 | 104 | * Get all frontend scripts. |
| 77 | 105 | * |
| 78 | 106 | * @return void |
| 79 | 107 | */ |
| @@ -87,13 +115,19 @@ | ||
| 87 | 115 | * @return object |
| 88 | 116 | */ |
| 89 | 117 | private function get_public_styles() { |
| 90 | 118 | $rtl_suffix = is_rtl() ? '-rtl' : ''; |
| 119 | + $rtl_dir = is_rtl() ? trailingslashit( 'rtl' ) : trailingslashit( 'css' ); | |
| 120 | + | |
| 91 | 121 | $this->styles[] = [ |
| 122 | + 'handle' => 'rtsb-odometer', | |
| 123 | + 'src' => rtsb()->get_assets_uri( 'vendor/odometer/css/odometer.min.css' ), | |
| 124 | + ]; | |
| 125 | + | |
| 126 | + $this->styles[] = [ | |
| 92 | 127 | 'handle' => 'rtsb-fonts', |
| 93 | 128 | 'src' => rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ), |
| 94 | 129 | ]; |
| 95 | - | |
| 96 | 130 | if ( rtsb()->has_pro() ) { |
| 97 | 131 | $this->styles[] = [ |
| 98 | 132 | 'handle' => 'rtsb-noui-slider', |
| 99 | 133 | 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.css' ), |
| @@ -99,18 +133,25 @@ | ||
| 99 | 133 | 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.css' ), |
| 100 | 134 | ]; |
| 101 | 135 | } |
| 102 | 136 | |
| 103 | - $this->styles[] = [ | |
| 104 | - 'handle' => 'rtsb-frontend', | |
| 105 | - 'src' => rtsb()->get_assets_uri( 'css/frontend/frontend' . $rtl_suffix . '.css' ), | |
| 106 | - ]; | |
| 137 | + $pro_version = defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : '0'; | |
| 138 | + $addon_condition = version_compare( $pro_version, '1.9.0', '<' ); | |
| 107 | 139 | |
| 108 | - $this->styles[] = [ | |
| 109 | - 'handle' => 'swiper', | |
| 110 | - 'src' => rtsb()->get_assets_uri( 'vendor/swiper/css/swiper-bundle.min.css' ), | |
| 111 | - ]; | |
| 112 | - | |
| 140 | + if ( ! rtsb()->has_pro() && Fns::is_optimization_enabled() ) { | |
| 141 | + $this->styles[] = AssetRegistry::instance()->load_optimized_assets(); | |
| 142 | + } else { | |
| 143 | + if ( $addon_condition ) { | |
| 144 | + $this->styles[] = [ | |
| 145 | + 'handle' => 'rtsb-general-addons', | |
| 146 | + 'src' => rtsb()->get_assets_uri( $rtl_dir . 'frontend/general-addons' . $rtl_suffix . '.css' ), | |
| 147 | + ]; | |
| 148 | + } | |
| 149 | + $this->styles[] = [ | |
| 150 | + 'handle' => 'rtsb-frontend', | |
| 151 | + 'src' => rtsb()->get_assets_uri( $rtl_dir . 'frontend/frontend' . $rtl_suffix . '.css' ), | |
| 152 | + ]; | |
| 153 | + } | |
| 113 | 154 | if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) { |
| 114 | 155 | $this->styles[] = [ |
| 115 | 156 | 'handle' => 'photoswipe', |
| 116 | 157 | 'src' => plugins_url( 'assets/css/photoswipe/photoswipe.min.css', WC_PLUGIN_FILE ), |
| @@ -138,19 +179,24 @@ | ||
| 138 | 179 | */ |
| 139 | 180 | private function get_public_scripts() { |
| 140 | 181 | $this->scripts[] = [ |
| 141 | 182 | 'handle' => 'swiper', |
| 142 | - 'src' => rtsb()->get_assets_uri( 'vendor/swiper/js/swiper-bundle.min.js' ), | |
| 183 | + 'src' => esc_url( $this->get_swiper_url() ), | |
| 143 | 184 | 'deps' => [ 'jquery' ], |
| 144 | 185 | 'footer' => true, |
| 145 | 186 | ]; |
| 146 | - | |
| 147 | 187 | $this->scripts[] = [ |
| 148 | - 'handle' => 'rtsb-imagesloaded', | |
| 149 | - 'src' => rtsb()->get_assets_uri( 'vendor/isotope/imagesloaded.pkgd.min.js' ), | |
| 188 | + 'handle' => 'rtsb-waypoints', | |
| 189 | + 'src' => rtsb()->get_assets_uri( 'vendor/waypoints/js/jquery.waypoints.min.js' ), | |
| 150 | 190 | 'deps' => [ 'jquery' ], |
| 151 | 191 | 'footer' => true, |
| 152 | 192 | ]; |
| 193 | + $this->scripts[] = [ | |
| 194 | + 'handle' => 'rtsb-odometer', | |
| 195 | + 'src' => rtsb()->get_assets_uri( 'vendor/odometer/js/odometer.min.js' ), | |
| 196 | + 'deps' => [ 'jquery' ], | |
| 197 | + 'footer' => true, | |
| 198 | + ]; | |
| 153 | 199 | |
| 154 | 200 | $this->scripts[] = [ |
| 155 | 201 | 'handle' => 'rtsb-tipsy', |
| 156 | 202 | 'src' => rtsb()->get_assets_uri( 'vendor/tipsy/tipsy.min.js' ), |
| @@ -209,16 +255,34 @@ | ||
| 209 | 255 | 'src' => rtsbpro()->get_assets_uri( 'vendors/sticky-sidebar/sticky-sidebar.min.js' ), |
| 210 | 256 | 'deps' => [ 'jquery' ], |
| 211 | 257 | 'footer' => true, |
| 212 | 258 | ]; |
| 259 | + | |
| 260 | + $this->scripts[] = [ | |
| 261 | + 'handle' => 'rtsb-popper', | |
| 262 | + 'src' => rtsbpro()->get_assets_uri( 'vendors/tippy/popper.min.js' ), | |
| 263 | + 'deps' => [ 'jquery' ], | |
| 264 | + 'footer' => true, | |
| 265 | + ]; | |
| 266 | + | |
| 267 | + $this->scripts[] = [ | |
| 268 | + 'handle' => 'rtsb-tippy', | |
| 269 | + 'src' => rtsbpro()->get_assets_uri( 'vendors/tippy/tippy.min.js' ), | |
| 270 | + 'deps' => [ 'jquery', 'rtsb-popper' ], | |
| 271 | + 'footer' => true, | |
| 272 | + ]; | |
| 213 | 273 | } |
| 214 | 274 | |
| 215 | - $this->scripts[] = [ | |
| 216 | - 'handle' => 'rtsb-public', | |
| 217 | - 'src' => rtsb()->get_assets_uri( 'js/frontend/frontend.js' ), | |
| 218 | - 'deps' => [ 'jquery', 'rtsb-imagesloaded', 'swiper' ], | |
| 219 | - 'footer' => true, | |
| 220 | - ]; | |
| 275 | + if ( ! rtsb()->has_pro() && Fns::is_optimization_enabled() ) { | |
| 276 | + $this->scripts[] = AssetRegistry::instance()->load_optimized_assets( 'js' ); | |
| 277 | + } else { | |
| 278 | + $this->scripts[] = [ | |
| 279 | + 'handle' => 'rtsb-public', | |
| 280 | + 'src' => rtsb()->get_assets_uri( 'js/frontend/frontend.js' ), | |
| 281 | + 'deps' => [ 'jquery', 'imagesloaded', 'swiper' ], | |
| 282 | + 'footer' => true, | |
| 283 | + ]; | |
| 284 | + } | |
| 221 | 285 | |
| 222 | 286 | return $this; |
| 223 | 287 | } |
| 224 | 288 | |
| @@ -228,8 +292,10 @@ | ||
| 228 | 292 | * @return void |
| 229 | 293 | */ |
| 230 | 294 | public function register_public_scripts() { |
| 231 | 295 | $this->get_public_assets(); |
| 296 | + $this->styles = array_filter( $this->styles ); | |
| 297 | + $this->scripts = array_filter( $this->scripts ); | |
| 232 | 298 | |
| 233 | 299 | // Register public styles. |
| 234 | 300 | foreach ( $this->styles as $style ) { |
| 235 | 301 | wp_register_style( $style['handle'], $style['src'], '', $this->version ); |
| @@ -250,8 +316,9 @@ | ||
| 250 | 316 | /** |
| 251 | 317 | * Register scripts. |
| 252 | 318 | */ |
| 253 | 319 | $this->register_public_scripts(); |
| 320 | + | |
| 254 | 321 | /** |
| 255 | 322 | * Enqueue scripts. |
| 256 | 323 | */ |
| 257 | 324 | if ( BuilderFns::is_builder_preview() && 'elementor' === Fns::page_edit_with( get_the_ID() ) ) { |
| @@ -257,9 +324,8 @@ | ||
| 257 | 324 | if ( BuilderFns::is_builder_preview() && 'elementor' === Fns::page_edit_with( get_the_ID() ) ) { |
| 258 | 325 | /** |
| 259 | 326 | * Styles. |
| 260 | 327 | */ |
| 261 | - wp_enqueue_style( 'swiper' ); | |
| 262 | 328 | wp_enqueue_style( 'photoswipe' ); |
| 263 | 329 | wp_enqueue_style( 'photoswipe-default-skin' ); |
| 264 | 330 | wp_enqueue_style( 'elementor-editor-style-fix' ); |
| 265 | 331 | wp_enqueue_style( 'woocommerce-general' ); |
| @@ -266,27 +332,31 @@ | ||
| 266 | 332 | |
| 267 | 333 | /** |
| 268 | 334 | * Scripts. |
| 269 | 335 | */ |
| 336 | + $handle = Fns::optimized_handle( 'rtsb-public' ); | |
| 337 | + | |
| 270 | 338 | wp_enqueue_script( 'flexslider' ); |
| 271 | 339 | wp_enqueue_script( 'wc-single-product' ); |
| 272 | - wp_dequeue_script( 'rtsb-public' ); | |
| 340 | + wp_dequeue_script( $handle ); | |
| 273 | 341 | wp_enqueue_script( 'swiper' ); |
| 274 | - wp_enqueue_script( 'rtsb-public' ); | |
| 342 | + | |
| 343 | + if ( Fns::is_optimization_enabled() ) { | |
| 344 | + Fns::enqueue_optimized_assets(); | |
| 345 | + } else { | |
| 346 | + wp_enqueue_script( $handle ); | |
| 347 | + } | |
| 275 | 348 | } |
| 276 | 349 | |
| 277 | - /** | |
| 278 | - * Styles. | |
| 279 | - */ | |
| 280 | - wp_enqueue_style( 'rtsb-fonts' ); | |
| 281 | - wp_enqueue_style( 'rtsb-frontend' ); | |
| 350 | + wp_enqueue_script( 'rtsb-tipsy' ); | |
| 282 | 351 | |
| 283 | - /** | |
| 284 | - * Scripts. | |
| 285 | - */ | |
| 286 | - wp_enqueue_script( 'rtsb-imagesloaded' ); | |
| 287 | - wp_enqueue_script( 'rtsb-tipsy' ); | |
| 288 | - wp_enqueue_script( 'rtsb-public' ); | |
| 352 | + if ( Fns::is_optimization_enabled() ) { | |
| 353 | + Fns::enqueue_optimized_assets(); | |
| 354 | + } else { | |
| 355 | + wp_enqueue_style( 'rtsb-fonts' ); | |
| 356 | + wp_enqueue_style( 'rtsb-frontend' ); | |
| 357 | + wp_enqueue_script( 'rtsb-public' ); | |
| 358 | + } | |
| 289 | 359 | |
| 290 | 360 | /** |
| 291 | 361 | * Localize script. |
| 292 | 362 | */ |
| @@ -299,22 +369,28 @@ | ||
| 299 | 369 | * @static |
| 300 | 370 | * @return void |
| 301 | 371 | */ |
| 302 | 372 | public static function localizeData() { |
| 373 | + $handle = Fns::optimized_handle( 'rtsb-public' ); | |
| 374 | + | |
| 303 | 375 | wp_localize_script( |
| 304 | - 'rtsb-public', | |
| 376 | + $handle, | |
| 305 | 377 | 'rtsbPublicParams', |
| 306 | 378 | [ |
| 307 | - 'ajaxUrl' => esc_url( self::$ajaxurl ), | |
| 308 | - 'homeurl' => home_url(), | |
| 309 | - 'wcCartUrl' => wc_get_cart_url(), | |
| 310 | - 'addedToCartText' => esc_html__( 'Product Added', 'shopbuilder' ), | |
| 311 | - 'browseCartText' => esc_html__( 'Browse Cart', 'shopbuilder' ), | |
| 312 | - 'noProductsText' => apply_filters( 'rtsb/global/no_products_text', esc_html__( 'No more products to load', 'shopbuilder' ) ), | |
| 313 | - 'notice' => [ | |
| 379 | + 'ajaxUrl' => esc_url( self::$ajaxurl ), | |
| 380 | + 'homeurl' => home_url(), | |
| 381 | + 'wcCartUrl' => wc_get_cart_url(), | |
| 382 | + 'addedToCartText' => esc_html__( 'Product Added', 'shopbuilder' ), | |
| 383 | + 'singleCartToastrText' => esc_html__( 'Successfully Added', 'shopbuilder' ), | |
| 384 | + 'singleCartBtnText' => apply_filters( 'rtsb/global/single_add_to_cart_success', esc_html__( 'Added to Cart', 'shopbuilder' ) ), | |
| 385 | + 'browseCartText' => esc_html__( 'Browse Cart', 'shopbuilder' ), | |
| 386 | + 'noProductsText' => apply_filters( 'rtsb/global/no_products_text', esc_html__( 'No more products to load', 'shopbuilder' ) ), | |
| 387 | + 'isOptimizationEnabled' => Fns::is_optimization_enabled(), | |
| 388 | + 'isLoaderEnabled' => Fns::enable_loader(), | |
| 389 | + 'notice' => [ | |
| 314 | 390 | 'position' => Fns::get_option( 'general', 'notification', 'notification_position', 'center-center' ), |
| 315 | 391 | ], |
| 316 | - rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ), | |
| 392 | + rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ), | |
| 317 | 393 | ] |
| 318 | 394 | ); |
| 319 | 395 | } |
| 320 | 396 | |
| @@ -327,9 +403,20 @@ | ||
| 327 | 403 | /** |
| 328 | 404 | * Styles. |
| 329 | 405 | */ |
| 330 | 406 | wp_register_style( 'rtsb-admin-app', rtsb()->get_assets_uri( 'css/backend/admin-settings.css' ), '', $this->version ); |
| 331 | - wp_register_style( 'rtsb-admin-global', rtsb()->get_assets_uri( 'css/backend/admin-global.css' ), '', $this->version ); | |
| 407 | + wp_register_style( 'rtsb-fonts', rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ), '', $this->version ); | |
| 408 | + | |
| 409 | + $current_screen = get_current_screen(); | |
| 410 | + | |
| 411 | + if ( 'edit-rtsb_builder' === $current_screen->id ) { | |
| 412 | + if ( ! function_exists( 'woocommerce_get_asset_url' ) ) { | |
| 413 | + include_once WC_ABSPATH . 'includes/wc-template-functions.php'; | |
| 414 | + } | |
| 415 | + | |
| 416 | + wp_deregister_style( 'select2' ); | |
| 417 | + wp_register_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 418 | + } | |
| 332 | 419 | wp_register_style( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'css/backend/template-builder.css' ), '', $this->version ); |
| 333 | 420 | |
| 334 | 421 | /** |
| 335 | 422 | * Scripts. |
| @@ -335,25 +422,47 @@ | ||
| 335 | 422 | * Scripts. |
| 336 | 423 | */ |
| 337 | 424 | wp_register_script( 'rtsb-admin-app', rtsb()->get_assets_uri( 'js/backend/admin-settings.js' ), '', $this->version, true ); |
| 338 | 425 | wp_register_script( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'js/backend/template-builder.js' ), '', $this->version, true ); |
| 339 | - | |
| 340 | 426 | } |
| 341 | 427 | |
| 342 | 428 | /** |
| 343 | 429 | * Enqueues admin scripts. |
| 344 | 430 | * |
| 345 | - * @param string $hook Hooks. | |
| 346 | - * | |
| 347 | 431 | * @return void |
| 348 | 432 | */ |
| 349 | - public function enqueue_backend_scripts( $hook ) { | |
| 433 | + public function enqueue_backend_scripts() { | |
| 434 | + ob_start(); ?> | |
| 435 | + #adminmenu .toplevel_page_rtsb .wp-menu-image img { | |
| 436 | + width: auto; | |
| 437 | + height: 22px; | |
| 438 | + padding: 4px 0; | |
| 439 | + box-sizing: content-box; | |
| 440 | + } | |
| 441 | + .post-type-rtsb_builder li#wp-admin-bar-WPML_ALS_all, | |
| 442 | + .post-type-rtsb_builder li.language_all{ | |
| 443 | + display: none; | |
| 444 | + } | |
| 350 | 445 | |
| 351 | - wp_enqueue_style( 'rtsb-admin-global' ); | |
| 446 | + <?php | |
| 447 | + $admin_global_style = ob_get_clean(); | |
| 448 | + // Speed Optimization. | |
| 449 | + wp_add_inline_style( 'admin-menu', $admin_global_style ); | |
| 352 | 450 | |
| 353 | 451 | global $pagenow; |
| 354 | 452 | |
| 355 | - if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && 'rtsb-settings' === $_GET['page'] ) { | |
| 453 | + $whitelisted_pages = [ 'rtsb-settings', 'rtsb-get-help', 'rtsb-themes' ]; | |
| 454 | + $current_page = ! empty( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 455 | + | |
| 456 | + if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && in_array( $current_page, $whitelisted_pages, true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 457 | + /** | |
| 458 | + * Styles. | |
| 459 | + */ | |
| 460 | + wp_enqueue_style( 'rtsb-admin-app' ); | |
| 461 | + wp_enqueue_style( 'rtsb-fonts' ); | |
| 462 | + } | |
| 463 | + | |
| 464 | + if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && 'rtsb-settings' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 356 | 465 | // Elementor Console Error Fixed For "rtsb-settings" Page. |
| 357 | 466 | wp_dequeue_script( 'elementor-admin-top-bar' ); |
| 358 | 467 | wp_dequeue_script( 'elementor-common' ); |
| 359 | 468 | wp_dequeue_script( 'elementor-dev-tools' ); |
| @@ -360,8 +469,9 @@ | ||
| 360 | 469 | wp_dequeue_script( 'elementor-web-cli' ); |
| 361 | 470 | wp_dequeue_script( 'elementor-import-export-admin' ); |
| 362 | 471 | wp_dequeue_script( 'elementor-app-loader' ); |
| 363 | 472 | wp_dequeue_script( 'elementor-admin-modules' ); |
| 473 | + wp_dequeue_script( 'elementor-ai-media-library' ); | |
| 364 | 474 | wp_dequeue_script( 'elementor-admin' ); |
| 365 | 475 | |
| 366 | 476 | wp_dequeue_style( 'elementor-admin-top-bar' ); |
| 367 | 477 | wp_dequeue_style( 'elementor-admin' ); |
| @@ -368,15 +478,11 @@ | ||
| 368 | 478 | wp_dequeue_style( 'e-theme-ui-light' ); |
| 369 | 479 | wp_dequeue_style( 'elementor-common' ); |
| 370 | 480 | |
| 371 | 481 | /** |
| 372 | - * Styles. | |
| 373 | - */ | |
| 374 | - wp_enqueue_style( 'rtsb-admin-app' ); | |
| 375 | - | |
| 376 | - /** | |
| 377 | 482 | * Scripts. |
| 378 | 483 | */ |
| 484 | + wp_enqueue_media(); | |
| 379 | 485 | wp_enqueue_script( 'updates' ); |
| 380 | 486 | wp_enqueue_script( 'rtsb-admin-app' ); |
| 381 | 487 | wp_localize_script( |
| 382 | 488 | 'rtsb-admin-app', |
| @@ -381,16 +487,23 @@ | ||
| 381 | 487 | wp_localize_script( |
| 382 | 488 | 'rtsb-admin-app', |
| 383 | 489 | 'rtsbParams', |
| 384 | 490 | [ |
| 385 | - 'ajaxurl' => esc_url( self::$ajaxurl ), | |
| 386 | - 'homeurl' => home_url(), | |
| 387 | - 'restApiUrl' => esc_url_raw( rest_url() ), | |
| 388 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 389 | - 'nonce' => wp_create_nonce( rtsb()->nonceText ), | |
| 390 | - 'sections' => Settings::instance()->get_sections(), | |
| 391 | - 'pages' => Fns::get_pages(), | |
| 392 | - 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no' | |
| 491 | + 'ajaxurl' => esc_url( self::$ajaxurl ), | |
| 492 | + 'homeurl' => home_url(), | |
| 493 | + 'adminLogo' => rtsb()->get_assets_uri( 'images/icon/ShopBuilder-Logo.svg' ), | |
| 494 | + 'restApiUrl' => esc_url_raw( rest_url() ), | |
| 495 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 496 | + 'nonce' => wp_create_nonce( rtsb()->nonceText ), | |
| 497 | + 'pages' => Fns::get_pages(), | |
| 498 | + 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no', | |
| 499 | + 'proVersion' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : '0', | |
| 500 | + 'updateRates' => esc_html__( 'Update All Rates', 'shopbuilder' ), | |
| 501 | + 'sections' => Settings::instance()->get_sections(), | |
| 502 | + 'userRoles' => Fns::get_all_user_roles(), | |
| 503 | + 'hasElementor' => defined( 'ELEMENTOR_VERSION' ), | |
| 504 | + 'loadElementor' => Fns::should_load_elementor_scripts(), | |
| 505 | + 'isOptimizationEnabled' => Fns::is_optimization_enabled(), | |
| 393 | 506 | ] |
| 394 | 507 | ); |
| 395 | 508 | } else { |
| 396 | 509 | $current_screen = get_current_screen(); |
| @@ -403,9 +516,9 @@ | ||
| 403 | 516 | * Styles. |
| 404 | 517 | */ |
| 405 | 518 | wp_enqueue_style( 'rtsb-templatebuilder' ); |
| 406 | 519 | |
| 407 | - wp_enqueue_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) ); | |
| 520 | + wp_enqueue_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 408 | 521 | |
| 409 | 522 | wp_enqueue_script( 'selectWoo' ); |
| 410 | 523 | /** |
| 411 | 524 | * Scripts. |
| @@ -418,9 +531,9 @@ | ||
| 418 | 531 | [ |
| 419 | 532 | 'ajaxurl' => esc_url( self::$ajaxurl ), |
| 420 | 533 | 'homeurl' => home_url(), |
| 421 | 534 | rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ), |
| 422 | - 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no' | |
| 535 | + 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no', | |
| 423 | 536 | ] |
| 424 | 537 | ); |
| 425 | 538 | } |
| 426 | 539 | } |
| @@ -440,8 +553,9 @@ | ||
| 440 | 553 | |
| 441 | 554 | if ( ! empty( $notification_color ) ) { |
| 442 | 555 | $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{color:{$notification_color}}"; |
| 443 | 556 | $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success:before{background-color:{$notification_color}}"; |
| 557 | + $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-close-button{color:{$notification_color}}"; | |
| 444 | 558 | } |
| 445 | 559 | |
| 446 | 560 | if ( ! empty( $notification_bgcolor ) ) { |
| 447 | 561 | $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{background-color:{$notification_bgcolor}}"; |
| @@ -451,8 +565,33 @@ | ||
| 451 | 565 | $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success a{color:{$notification_button_color}}"; |
| 452 | 566 | } |
| 453 | 567 | |
| 454 | 568 | if ( ! empty( $dynamic_css ) ) { |
| 455 | - wp_add_inline_style( 'rtsb-frontend', $dynamic_css ); | |
| 569 | + wp_add_inline_style( Fns::optimized_handle( 'rtsb-frontend' ), $dynamic_css ); | |
| 456 | 570 | } |
| 571 | + } | |
| 572 | + | |
| 573 | + /** | |
| 574 | + * Get the appropriate Swiper JS file URL. | |
| 575 | + * | |
| 576 | + * @return string | |
| 577 | + */ | |
| 578 | + private function get_swiper_url() { | |
| 579 | + $default_swiper_url = rtsb()->get_assets_uri( 'vendor/swiper/js/swiper-bundle.min.js' ); | |
| 580 | + | |
| 581 | + if ( defined( 'ELEMENTOR_ASSETS_PATH' ) && defined( 'ELEMENTOR_ASSETS_URL' ) ) { | |
| 582 | + $experiment = get_option( 'elementor_experiment-e_swiper_latest' ); | |
| 583 | + | |
| 584 | + $el_relative_path = ( 'active' === $experiment || 'default' === $experiment ) | |
| 585 | + ? 'lib/swiper/v8/swiper.min.js' | |
| 586 | + : 'lib/swiper/swiper.min.js'; | |
| 587 | + | |
| 588 | + $el_full_path = ELEMENTOR_ASSETS_PATH . $el_relative_path; | |
| 589 | + | |
| 590 | + if ( file_exists( $el_full_path ) ) { | |
| 591 | + return ELEMENTOR_ASSETS_URL . $el_relative_path; | |
| 592 | + } | |
| 593 | + } | |
| 594 | + | |
| 595 | + return $default_swiper_url; | |
| 457 | 596 | } |
| 458 | 597 | } |