get_all_settings(); if ( isset( $settings['builder_compat'] ) && empty( $settings['builder_compat'] ) ) { return; } } if ( ! function_exists( 'add_filter' ) ) { return; } add_filter( 'qwsc_asset_protected_handles', array( $this, 'filter_asset_handles' ) ); add_filter( 'qwsc_js_delay_exclusions', array( $this, 'filter_delay_exclusions' ) ); add_filter( 'qwsc_rucss_safelist', array( $this, 'filter_rucss_safelist' ) ); add_filter( 'qwsc_critical_css_safelist', array( $this, 'filter_critical_safelist' ) ); } /** * @return bool */ public static function has_elementor() { return defined( 'ELEMENTOR_VERSION' ) || class_exists( '\Elementor\Plugin', false ); } /** * @return bool */ public static function has_divi() { return defined( 'ET_BUILDER_VERSION' ) || function_exists( 'et_setup_theme' ) || defined( 'ET_CORE_VERSION' ); } /** * Block editor / FSE themes always “present”; pack still useful for front CSS classes. * * @return bool */ public static function has_gutenberg() { return true; } /** * Active pack ids. * * @return string[] */ public static function active_packs() { $packs = array( 'gutenberg' ); if ( self::has_elementor() ) { $packs[] = 'elementor'; } if ( self::has_divi() ) { $packs[] = 'divi'; } return $packs; } /** * @return string[] */ public static function elementor_handles() { return array( 'elementor-frontend', 'elementor-frontend-modules', 'elementor-webpack-runtime', 'elementor-pro-frontend', 'elementor-waypoints', 'elementor-dialog', 'elementor-sticky', 'elementor-common', 'elementor-app-loader', 'swiper', 'share-link', 'jquery-numerator', 'imagesloaded', 'backbone-marionette', 'backbone-radio', 'elementor-gallery', 'e-sticky', 'e-swiper', ); } /** * @return string[] */ public static function divi_handles() { return array( 'et-builder-modules-global-functions-script', 'et-builder-modules-script', 'divi-custom-script', 'et-core-common', 'easypiechart', 'salvattore', 'fitvids', 'magnific-popup', 'et-core-api-spam-recaptcha', ); } /** @return string[] */ public static function divi_handles_clean() { return self::divi_handles(); } /** * @return string[] */ public static function gutenberg_handles() { return array( 'wp-block-library', 'wp-block-library-theme', 'classic-theme-styles', 'global-styles', 'wp-edit-blocks', 'wp-components', 'wp-element', 'wp-blocks', 'wp-i18n', 'wp-hooks', 'wp-data', 'wp-api-fetch', ); } /** * CSS class/token safelist for RUCSS / critical. * * @return string[] */ public static function elementor_css_tokens() { return array( 'elementor', 'elementor-section', 'elementor-container', 'elementor-widget', 'elementor-element', 'elementor-column', 'elementor-icon', 'elementor-button', 'elementor-heading', 'elementor-motion-effects', 'e-', 'swiper', 'swiper-slide', 'swiper-wrapper', 'dialog-widget', 'animated', 'elementor-invisible', ); } /** * @return string[] */ public static function divi_css_tokens() { return array( 'et_pb_', 'et_pb_section', 'et_pb_row', 'et_pb_column', 'et_pb_module', 'et_pb_button', 'et_pb_text', 'et_pb_image', 'et_fixed_nav', 'et-db', 'et_animated', 'et-waypoint', ); } /** * @return string[] */ public static function gutenberg_css_tokens() { return array( 'wp-block', 'wp-block-group', 'wp-block-columns', 'wp-block-column', 'wp-block-cover', 'wp-block-image', 'wp-block-navigation', 'wp-block-button', 'wp-block-buttons', 'wp-block-gallery', 'wp-block-query', 'wp-block-post', 'has-background', 'has-text-color', 'is-layout-', 'is-style-', 'alignwide', 'alignfull', ); } /** * @param string[] $handles Handles. * @return string[] */ public function filter_asset_handles( $handles ) { $handles = is_array( $handles ) ? $handles : array(); if ( self::has_elementor() ) { $handles = array_merge( $handles, self::elementor_handles() ); } if ( self::has_divi() ) { $handles = array_merge( $handles, self::divi_handles_clean() ); } $handles = array_merge( $handles, self::gutenberg_handles() ); return array_values( array_unique( array_map( 'strval', $handles ) ) ); } /** * @param string[] $list Exclusions. * @return string[] */ public function filter_delay_exclusions( $list ) { $list = is_array( $list ) ? $list : array(); if ( self::has_elementor() ) { $list = array_merge( $list, self::elementor_handles(), array( 'elementor', 'elementor-pro' ) ); } if ( self::has_divi() ) { $list = array_merge( $list, self::divi_handles_clean(), array( 'divi-', 'et-builder', 'et_pb_' ) ); } $list = array_merge( $list, self::gutenberg_handles() ); return array_values( array_unique( array_map( 'strval', $list ) ) ); } /** * @param string[] $list Safelist. * @return string[] */ public function filter_rucss_safelist( $list ) { $list = is_array( $list ) ? $list : array(); $list = array_merge( $list, self::gutenberg_css_tokens() ); if ( self::has_elementor() ) { $list = array_merge( $list, self::elementor_css_tokens() ); } if ( self::has_divi() ) { $list = array_merge( $list, self::divi_css_tokens() ); } return array_values( array_unique( array_map( 'strval', $list ) ) ); } /** * @param string[] $list Safelist. * @return string[] */ public function filter_critical_safelist( $list ) { return $this->filter_rucss_safelist( $list ); } }