Astra_Enqueue_Scripts::enqueue_scripts()
Enqueue Scripts
Description
Source
File: inc/core/class-astra-enqueue-scripts.php
public function enqueue_scripts() { if ( false === self::enqueue_theme_assets() ) { return; } /* Directory and Extension */ $file_prefix = ( SCRIPT_DEBUG ) ? '' : '.min'; $dir_name = ( SCRIPT_DEBUG ) ? 'unminified' : 'minified'; $js_uri = ASTRA_THEME_URI . 'assets/js/' . $dir_name . '/'; $css_uri = ASTRA_THEME_URI . 'assets/css/' . $dir_name . '/'; /** * IE Only Js and CSS Files. */ // Flexibility.js for flexbox IE10 support. wp_enqueue_script( 'astra-flexibility', $js_uri . 'flexibility' . $file_prefix . '.js', array(), ASTRA_THEME_VERSION, false ); wp_add_inline_script( 'astra-flexibility', 'flexibility(document.documentElement);' ); wp_script_add_data( 'astra-flexibility', 'conditional', 'IE' ); // Polyfill for CustomEvent for IE. wp_register_script( 'astra-customevent', $js_uri . 'custom-events-polyfill' . $file_prefix . '.js', array(), ASTRA_THEME_VERSION, false ); wp_register_style( 'astra-galleries-css', $css_uri . 'galleries' . $file_prefix . '.css', array(), ASTRA_THEME_VERSION, 'all' ); // All assets. $all_assets = self::theme_assets(); $styles = $all_assets['css']; $scripts = $all_assets['js']; if ( is_array( $styles ) && ! empty( $styles ) ) { // Register & Enqueue Styles. foreach ( $styles as $key => $style ) { $dependency = array(); // Add dynamic CSS dependency for all styles except for theme's style.css. if ( 'astra-theme-css' !== $key && class_exists( 'Astra_Cache_Base' ) ) { if ( ! Astra_Cache_Base::inline_assets() ) { $dependency[] = 'astra-theme-dynamic'; } } // Generate CSS URL. $css_file = $css_uri . $style . $file_prefix . '.css'; // Register. wp_register_style( $key, $css_file, $dependency, ASTRA_THEME_VERSION, 'all' ); // Enqueue. wp_enqueue_style( $key ); // RTL support. wp_style_add_data( $key, 'rtl', 'replace' ); } } // Fonts - Render Fonts. Astra_Fonts::render_fonts(); /** * Inline styles */ add_filter( 'astra_dynamic_theme_css', array( 'Astra_Dynamic_CSS', 'return_output' ) ); add_filter( 'astra_dynamic_theme_css', array( 'Astra_Dynamic_CSS', 'return_meta_output' ) ); $menu_animation = astra_get_option( 'header-main-submenu-container-animation' ); // Submenu Container Animation for header builder. if ( true === Astra_Builder_Helper::$is_header_footer_builder_active ) { for ( $index = 1; $index <= Astra_Builder_Helper::$component_limit; $index++ ) { $menu_animation_enable = astra_get_option( 'header-menu' . $index . '-submenu-container-animation' ); if ( Astra_Builder_Helper::is_component_loaded( 'menu-' . $index, 'header' ) && ! empty( $menu_animation_enable ) ) { $menu_animation = 'is_animated'; break; } } } $rtl = ( is_rtl() ) ? '-rtl' : ''; if ( ! empty( $menu_animation ) || is_customize_preview() ) { if ( class_exists( 'Astra_Cache' ) ) { Astra_Cache::add_css_file( ASTRA_THEME_DIR . 'assets/css/' . $dir_name . '/menu-animation' . $rtl . $file_prefix . '.css' ); } else { wp_register_style( 'astra-menu-animation', $css_uri . 'menu-animation' . $file_prefix . '.css', null, ASTRA_THEME_VERSION, 'all' ); wp_enqueue_style( 'astra-menu-animation' ); } } if ( ! class_exists( 'Astra_Cache' ) ) { $theme_css_data = apply_filters( 'astra_dynamic_theme_css', '' ); wp_add_inline_style( 'astra-theme-css', $theme_css_data ); } if ( astra_is_amp_endpoint() ) { return; } // Comment assets. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } if ( is_array( $scripts ) && ! empty( $scripts ) ) { // Register & Enqueue Scripts. foreach ( $scripts as $key => $script ) { // Register. wp_register_script( $key, $js_uri . $script . $file_prefix . '.js', array(), ASTRA_THEME_VERSION, true ); // Enqueue. wp_enqueue_script( $key ); } } $astra_localize = array( 'break_point' => astra_header_break_point(), // Header Break Point. 'isRtl' => is_rtl(), ); wp_localize_script( 'astra-theme-js', 'astra', apply_filters( 'astra_theme_js_localize', $astra_localize ) ); }
Expand full source code Collapse full source code View on Trac