This commit is contained in:
2026-10-06 18:51:23 -06:00
parent 8424dacd03
commit e2c26b7f21
4223 changed files with 737986 additions and 53 deletions
@@ -0,0 +1,161 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
use WP_Rocket\Admin\Options_Data;
/**
* Compatibility class for Avada theme
*/
class Avada extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'avada';
/**
* Options instance
*
* @var Options_Data
*/
private $options;
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.3.1
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'avada_clear_dynamic_css_cache' => 'clean_domain',
'rocket_exclude_defer_js' => 'exclude_defer_js',
'rocket_maybe_disable_lazyload_helper' => 'maybe_disable_lazyload',
'fusion_cache_reset_after' => 'clean_domain',
'update_option_fusion_options' => [ 'maybe_deactivate_lazyload', 10, 2 ],
'rocket_wc_product_gallery_delay_js_exclusions' => 'exclude_delay_js',
'init' => 'disable_compilers',
'rocket_lazyload_bg_images_regex' => 'fix_regex_lazyload_bg_images',
];
}
/**
* Constructor
*
* @param Options_Data $options WP Rocket options instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* When Avada theme purge its own cache.
* Clear WP Rocket cache when Avada dynamic CSS is updated.
*
* @return void
*/
public function clean_domain() {
rocket_clean_domain();
}
/**
* Deactivate WP Rocket lazyload if Avada lazyload is enabled.
*
* @since 3.3.4
*
* @param string $old_value Previous Avada option value.
* @param string $value New Avada option value.
* @return void
*/
public function maybe_deactivate_lazyload( $old_value, $value ) {
if (
empty( $old_value['lazy_load'] )
||
( ! empty( $value['lazy_load'] ) && 'avada' === $value['lazy_load'] )
) {
update_rocket_option( 'lazyload', 0 );
}
}
/**
* Excludes Avada Google Maps JS files from defer JS
*
* @param array $exclude_defer_js Array of JS filepaths to be excluded.
* @return array
*/
public function exclude_defer_js( $exclude_defer_js ) {
$exclude_defer_js[] = '/jquery-?[0-9.]*(.min|.slim|.slim.min)?.js';
$exclude_defer_js[] = 'maps.googleapis.com';
return $exclude_defer_js;
}
/**
* Disable WP Rocket lazyload field if Avada lazyload is enabled
*
* @since 3.3.4
* @param array $disable_images_lazyload Array with plugins which disable lazyload functionality.
* @return array
*/
public function maybe_disable_lazyload( $disable_images_lazyload ) {
$avada_options = get_option( 'fusion_options' );
if ( empty( $avada_options['lazy_load'] ) ) {
return $disable_images_lazyload;
}
if ( ! empty( $avada_options['lazy_load'] && 'avada' !== $avada_options['lazy_load'] ) ) {
return $disable_images_lazyload;
}
$disable_images_lazyload[] = __( 'Avada', 'rocket' );
return $disable_images_lazyload;
}
/**
* Excludes some Avada JS from delay JS execution when WC product gallery has images
*
* @since 3.10.2
*
* @param array $exclusions Array of exclusion patterns.
*
* @return array
*/
public function exclude_delay_js( $exclusions ): array {
$base_path = wp_parse_url( get_stylesheet_directory_uri(), PHP_URL_PATH );
if ( empty( $base_path ) ) {
return $exclusions;
}
$exclusions[] = $base_path . '/includes/lib/assets/min/js/library/jquery.flexslider.js';
$exclusions[] = $base_path . '/assets/min/js/general/avada-woo-product-images.js';
return $exclusions;
}
/**
* Disable CSS and JS combine file from Avada.
*/
public function disable_compilers() {
if ( $this->options->get( 'remove_unused_css', false ) && ! defined( 'FUSION_DISABLE_COMPILERS' ) ) {
define( 'FUSION_DISABLE_COMPILERS', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
}
}
/**
* Add a fix to the lazyload regex on background images.
*
* @param string $regex regex used to deleted background images.
*
* @return string
*/
public function fix_regex_lazyload_bg_images( $regex ) {
return '(--awb-)?' . $regex;
}
}
@@ -0,0 +1,84 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class Bridge extends ThirdpartyTheme {
use ReturnTypesTrait;
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'bridge';
/**
* Options instance
*
* @var Options_Data
*/
private $options;
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.3.1
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'rocket_lazyload_background_images' => 'return_false',
'update_option_qode_options_proya' => [ 'maybe_clear_cache', 10, 2 ],
];
}
/**
* Constructor
*
* @param Options_Data $options WP Rocket options instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* Maybe clear WP Rocket cache when Bridge custom CSS/JS is updated
*
* @since 3.3.7
*
* @param array $old_value Previous option values.
* @param array $new_value New option values.
* @return void
*/
public function maybe_clear_cache( $old_value, $new_value ) {
$clear = false;
if ( $this->options->get( 'minify_css', 0 ) ) {
if ( isset( $old_value['custom_css'], $new_value['custom_css'] ) && $old_value['custom_css'] !== $new_value['custom_css'] ) {
$clear = true;
}
if ( isset( $old_value['custom_svg_css'], $new_value['custom_svg_css'] ) && $old_value['custom_svg_css'] !== $new_value['custom_svg_css'] ) {
$clear = true;
}
}
if ( $this->options->get( 'minify_js', 0 ) ) {
if ( isset( $old_value['custom_js'], $new_value['custom_js'] ) && $old_value['custom_js'] !== $new_value['custom_js'] ) {
$clear = true;
}
}
if ( $clear ) {
rocket_clean_domain();
rocket_clean_minify();
}
}
}
@@ -0,0 +1,363 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
use WP_Rocket\Admin\{Options, Options_Data};
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
use WP_Rocket\Engine\Optimization\RUCSS\Controller\UsedCSS;
class Divi extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'divi';
/**
* Options API instance.
*
* @var Options
*/
private $options_api;
/**
* WP Rocket options instance.
*
* @var Options_Data
*/
private $options;
/**
* Delay JS HTML class.
*
* @var HTML
*/
private $delayjs_html;
/**
* Used CSS controller instance.
*
* @var UsedCSS
*/
private $used_css;
/**
* Instantiate the class
*
* @param Options $options_api Options API instance.
* @param Options_Data $options WP Rocket options instance.
* @param HTML $delayjs_html DelayJS HTML class.
* @param UsedCSS $used_css Used CSS controller instance.
*/
public function __construct( Options $options_api, Options_Data $options, HTML $delayjs_html, UsedCSS $used_css ) {
$this->options_api = $options_api;
$this->options = $options;
$this->delayjs_html = $delayjs_html;
$this->used_css = $used_css;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
$events = [
'switch_theme' => [ 'maybe_disable_youtube_preview', PHP_INT_MAX, 2 ],
'rocket_specify_dimension_images' => 'disable_image_dimensions_height_percentage',
];
if ( ! self::is_current_theme() ) {
return $events;
}
$events['rocket_exclude_js'] = 'exclude_js';
$events['rocket_maybe_disable_youtube_lazyload_helper'] = 'add_divi_to_description';
$events['wp_enqueue_scripts'] = 'disable_divi_jquery_body';
$events['wp'] = 'disable_dynamic_css_on_rucss';
$events['after_setup_theme'] = 'remove_assets_generated';
$events['et_save_post'] = 'handle_save_template';
$events['admin_notices'] = 'handle_divi_admin_notice';
$slug = rocket_get_constant( 'WP_ROCKET_SLUG', 'wp_rocket_settings' );
$events[ 'update_option_' . $slug ] = [ 'remove_transient_when_enabling_rucss_option', 10, 2 ];
$events['rocket_after_clean_used_css'] = 'clear_divi_notice';
$events['wp_ajax_et_theme_builder_api_save'] = [ 'show_rucss_notice_with_save_changes', 9 ];
return $events;
}
/**
* Excludes Divi's Salvatorre script from JS minification
*
* Prevent an error after minification/concatenation
*
* @since 3.6.3
*
* @param array $excluded_js An array of JS paths to be excluded.
*
* @return array the updated array of paths
*/
public function exclude_js( $excluded_js ) {
if ( ! rocket_get_constant( 'ET_BUILDER_URI' ) ) {
return $excluded_js;
}
$excluded_js[] = str_replace( home_url(), '', rocket_get_constant( 'ET_BUILDER_URI' ) . '/scripts/salvattore.min.js' );
return $excluded_js;
}
/**
* Disables the Replace Youtube iframe by preview thumbnail option if new theme (or parent) is Divi
*
* @since 3.6.3
*
* @param string $name Name of the new theme.
* @param WP_Theme $theme instance of the new theme.
*
* @return void
*/
public function maybe_disable_youtube_preview( $name, $theme ) {
if ( ! self::is_current_theme( $theme ) ) {
return;
}
$this->options->set( 'lazyload_youtube', 0 );
$this->options_api->set( 'settings', $this->options->get_options() );
}
/**
* Adds Divi to the array of items disabling Youtube lazyload
*
* @since 3.6.3
*
* @param array $disable_youtube_lazyload Array of items names.
*
* @return array
*/
public function add_divi_to_description( $disable_youtube_lazyload ) {
if ( ! self::is_current_theme() ) {
return $disable_youtube_lazyload;
}
$disable_youtube_lazyload[] = 'Divi';
return $disable_youtube_lazyload;
}
/**
* Disables setting explicit dimensions on images where Divi calculates height as percentage.
*
* @since 3.8.2
*
* @param array $images The array of images selected for adding image dimensions.
*
* @return array The array without images using data-height-percentage.
*/
public function disable_image_dimensions_height_percentage( array $images ) {
foreach ( $images as $key => $image ) {
if ( false !== strpos( strtolower( $image ), 'data-height-percentage' ) ) {
unset( $images[ $key ] );
}
}
return $images;
}
/**
* Disable divi jquery body.
*
* @since 3.9.3
*/
public function disable_divi_jquery_body() {
if (
$this->delayjs_html->is_allowed()
&& defined( 'ET_CORE_VERSION' )
&& version_compare( ET_CORE_VERSION, '4.10', '>=' )
) {
add_filter( 'et_builder_enable_jquery_body', '__return_false' );
}
}
/**
* Disable Divi dynamic CSS when RUCSS is activated
*
* @return void
*/
public function disable_dynamic_css_on_rucss() {
if ( ! $this->options->get( 'remove_unused_css', false ) ) {
return;
}
add_filter( 'et_use_dynamic_css', '__return_false' );
}
/**
* Remove dynamic late assets action.
*
* @return void
*/
public function remove_assets_generated() {
remove_all_actions( 'et_dynamic_late_assets_generated' );
}
/**
* Get layout IDs for a template.
*
* @param int $template_post_id Template post ID.
*
* @return array
*/
private function get_layout_ids( $template_post_id ) {
$allowed_post_types = [
'et_header_layout',
'et_footer_layout',
'et_body_layout',
];
$current_post_type = get_post_type( $template_post_id );
if ( ! in_array( $current_post_type, $allowed_post_types, true ) ) {
return [];
}
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
return (array) $wpdb->get_col(
$wpdb->prepare(
'SELECT post_id from ' . $wpdb->postmeta . ' WHERE meta_key = %s AND meta_value = %d',
'_' . $current_post_type . '_id',
$template_post_id
)
);
}
/**
* Is allowed for RUCSS notice functionality when saving templates.
*
* @return bool
*/
private function is_allowed_for_rucss() {
return $this->options->get( 'remove_unused_css', 0 )
&&
current_user_can( 'rocket_manage_options' );
}
/**
* Save template handler.
*
* @param int $template_post_id Template post ID.
*
* @return void
*/
public function handle_save_template( $template_post_id ) {
/**
* Filters Bypassing saving template functionality.
*
* @param bool $bypass Bypass save template functionality.
* @param int $template_post_id Currently saved template post id.
*/
if ( apply_filters( 'rocket_divi_bypass_save_template', false, $template_post_id ) ) {
return;
}
// If the transient is there, we don't need to do the check again as the admin notice will be there already.
if ( false !== get_transient( 'rocket_divi_notice' ) ) {
return;
}
$layout_post_ids = $this->get_layout_ids( $template_post_id );
if ( empty( $layout_post_ids ) ) {
return;
}
foreach ( $layout_post_ids as $layout_post_id ) {
if ( 'publish' !== get_post_status( $layout_post_id ) ) {
continue;
}
set_transient( 'rocket_divi_notice', true );
return;
}
}
/**
* Admin notices handler.
*
* @return void
*/
public function handle_divi_admin_notice() {
if ( ! $this->is_allowed_for_rucss() ) {
return;
}
$notice = get_transient( 'rocket_divi_notice' );
if ( ! $notice ) {
return;
}
rocket_notice_html(
[
'status' => 'warning',
'dismissible' => '',
'dismiss_button' => 'rocket_divi_notice',
'action' => 'clear_used_css',
'message' =>
sprintf( '%1$sWP Rocket:%2$s ', '<strong>', '</strong>' ) . // Splitting it because I think the plugin name is not a translatable string.
esc_html__( 'Your Divi template was updated. Clear the Used CSS if the layout, design or CSS styles were changed.', 'rocket' ),
]
);
}
/**
* Clear divi notice.
*
* @return void
*/
public function clear_divi_notice() {
delete_transient( 'rocket_divi_notice' );
}
/**
* Remove notice transient when enabling RUCSS.
*
* @param array $old_value An array of submitted values for the settings.
* @param array $new_value An array of previous values for the settings.
*
* @return void
*/
public function remove_transient_when_enabling_rucss_option( $old_value, $new_value ) {
if ( ! isset( $new_value['remove_unused_css'], $old_value['remove_unused_css'] ) ) {
return;
}
if ( $new_value['remove_unused_css'] === $old_value['remove_unused_css'] ) {
return;
}
if ( ! $new_value['remove_unused_css'] ) {
return;
}
if ( $this->used_css->has_one_completed_row_at_least() ) {
return;
}
$this->clear_divi_notice();
}
/**
* Set the transient when save changes button is clicked.
*
* @return void
*/
public function show_rucss_notice_with_save_changes() {
set_transient( 'rocket_divi_notice', true );
}
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Themes;
class Flatsome extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'flatsome';
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [ 'rocket_rucss_inline_content_exclusions' => 'preserve_patterns' ];
}
/**
* Preserves the CSS patterns when adding the used CSS to the page
*
* @since 3.11
*
* @param array $patterns Array of patterns to preserve.
*
* @return array
*/
public function preserve_patterns( $patterns ): array {
$preserve = [
'#section_',
'#text-box-',
'#banner-',
'#slider-',
'#gap-',
'#image_',
'#row-',
'#text-',
'#banner-grid-',
'#cats-',
'#col-',
'#gallery-',
'#instagram-',
'#map-',
'#page-header-',
'#pages-',
'#panel-',
'#portfolio-',
'#product-flip-',
'#product-grid-',
'#stack-',
'#timer-',
'#title-',
];
return array_merge( $patterns, $preserve );
}
}
@@ -0,0 +1,79 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
class Jevelin extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'jevelin';
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'rocket_rucss_inline_content_exclusions' => 'preserve_patterns',
];
}
/**
* Preserves the CSS patterns when adding the used CSS to the page
*
* @since 3.11.3
*
* @param array $patterns Array of patterns to preserve.
*
* @return array
*/
public function preserve_patterns( $patterns ): array {
return array_merge(
$patterns,
[
'#heading-',
'#button-',
'#image-points-',
'#image-comparison-',
'#partners-',
'#icon-',
'#text-block-',
'#instagram-feed-',
'#woocommerce-products-',
'#tabs-',
'#icon-group-',
'#alert-',
'#divider-',
'#image-gallery-',
'#portfolio-fancy-',
'#counter-',
'#text-group-',
'#piechart-',
'#single-image-',
'#progress-',
'#countdown-',
'#testimonials-',
'#portfolio-',
'#event-',
'.vc_column_',
'.vc_row_',
'.sh-empty-space-',
'.sh-element-titlebar-title-',
'.sh-footer-builder-widgets-',
'.sh-image-gallery-simple-',
'.header-navigation-',
'.sh-google-maps-',
'.sh-element-titlebar-breadcrumbs-',
'.sh-header-builder-',
'.sh-text-group-',
'.sh-footer-builder-title-',
]
);
}
}
@@ -0,0 +1,41 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
class MinimalistBlogger extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'minimalistblogger';
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'rocket_delay_js_exclusions' => 'exclude_jquery_from_delay_js',
];
}
/**
* Excludes some MinimalistBlogger JS from delay JS execution
*
* @since 3.11.3
*
* @param array $exclusions Array of exclusion patterns.
*
* @return array
*/
public function exclude_jquery_from_delay_js( array $exclusions = [] ) {
$exclusions[] = '\/jquery(-migrate)?-?([0-9.]+)?(.min|.slim|.slim.min)?.js(\?(.*))?( |\'|"|>)';
return $exclusions;
}
}
@@ -0,0 +1,48 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
class Polygon extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'polygon';
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'rocket_rucss_inline_content_exclusions' => 'add_rucss_content_excluded',
];
}
/**
* Add excluded elements to rocket_rucss_inline_content_exclusions filter.
*
* @param array $excluded excluded elements.
* @return array
*/
public function add_rucss_content_excluded( $excluded ) {
$excluded [] = '.expanding_bar_';
return $excluded;
}
/**
* Checks if the current theme (or parent) is Polygone
*
* @param WP_Theme $theme Instance of the theme.
*/
private static function is_polygon( $theme = null ) {
$theme = $theme instanceof WP_Theme ? $theme : wp_get_theme();
return ( 'polygon' === strtolower( $theme->get( 'Name' ) ) || 'polygon' === $theme->get_template() );
}
}
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Themes;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
class ServiceProvider extends AbstractServiceProvider {
/**
* The provides array is a way to let the container
* know that a service is provided by this service
* provider. Every service that is registered via
* this service provider must have an alias added
* to this array or it will be ignored.
*
* @var array
*/
protected $provides = [
'avada_subscriber',
'bridge_subscriber',
'divi',
'flatsome',
'jevelin',
'minimalist_blogger',
'polygon',
'uncode',
'xstore',
'themify',
'shoptimizer',
];
/**
* Registers the subscribers in the container
*
* @return void
*/
public function register() {
$options = $this->getContainer()->get( 'options' );
$this->getContainer()
->share( 'avada_subscriber', Avada::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'bridge_subscriber', Bridge::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'divi', Divi::class )
->addArgument( $this->getContainer()->get( 'options_api' ) )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'delay_js_html' ) )
->addArgument( $this->getContainer()->get( 'rucss_used_css_controller' ) )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'flatsome', Flatsome::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'jevelin', Jevelin::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'minimalist_blogger', MinimalistBlogger::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'polygon', Polygon::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'uncode', Uncode::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'xstore', Xstore::class )
->addTag( 'common_subscriber' );
$this->getContainer()->share( 'themify', Themify::class )
->addArgument( $options );
$this->getContainer()->share( 'shoptimizer', Shoptimizer::class );
}
}
@@ -0,0 +1,56 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
class Shoptimizer extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'shoptimizer';
/**
* Returns an array of events that this subscriber wants to listen to.
*
* The array key is the event name. The value can be:
*
* * The method name
* * An array with the method name and priority
* * An array with the method name, priority and number of accepted arguments
*
* For instance:
*
* * array('hook_name' => 'method_name')
* * array('hook_name' => array('method_name', $priority))
* * array('hook_name' => array('method_name', $priority, $accepted_args))
* * array('hook_name' => array(array('method_name_1', $priority_1, $accepted_args_1)), array('method_name_2', $priority_2, $accepted_args_2)))
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'rocket_exclude_defer_js' => 'exclude_jquery_deferjs_with_cart_drawer',
];
}
/**
* Exclude Jquery from defer JS.
*
* @param array $exclusions Excluded values from defer JS.
*
* @return array
*/
public function exclude_jquery_deferjs_with_cart_drawer( $exclusions ) {
if ( ! function_exists( 'shoptimizer_get_option' ) || ! shoptimizer_get_option( 'shoptimizer_layout_woocommerce_enable_sidebar_cart' ) ) {
return $exclusions;
}
$exclusions[] = '\/jquery(-migrate)?-?([0-9.]+)?(.min|.slim|.slim.min)?.js(\?(.*))?';
return $exclusions;
}
}
@@ -0,0 +1,162 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
use WP_Rocket\Admin\Options_Data;
class Themify extends ThirdpartyTheme {
/**
* WP Rocket options instance.
*
* @var Options_Data
*/
private $options;
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'themify-ultra';
/**
* Instantiate the class.
*
* @param Options_Data $options WP Rocket options instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'after_switch_theme' => 'disabling_concat_on_theme',
'update_option_' . rocket_get_constant( 'WP_ROCKET_SLUG', 'wp_rocket_settings' ) => [ 'disabling_concat_on_rucss', 10, 2 ],
'themify_save_data' => 'disable_concat_on_saving_data',
'themify_dev_mode' => 'maybe_enable_dev_mode',
];
}
/**
* Change the value on change theme.
*
* @return void
*/
public function disabling_concat_on_theme() {
$data = themify_get_data();
$remove_unused_css = $this->options->get( 'remove_unused_css', false );
if ( ! $remove_unused_css ) {
$data = $this->maybe_disable( $data );
}
if ( $remove_unused_css ) {
$data = $this->maybe_enable( $data );
}
themify_set_data( $data );
}
/**
* Disable concat on saving theme options.
*
* @param array $value theme options.
* @return array
*/
public function disable_concat_on_saving_data( $value ) {
if ( ! $this->options->get( 'remove_unused_css', false ) ) {
return $value;
}
return $this->maybe_enable( $value );
}
/**
* Disable concat on RUCSS enabled.
*
* @param array $old Old configurations.
* @param array $new New configurations.
*
* @return void
*/
public function disabling_concat_on_rucss( $old, $new ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound
if ( ! key_exists( 'remove_unused_css', $old ) || ! key_exists( 'remove_unused_css', $new ) || $old['remove_unused_css'] === $new['remove_unused_css'] ) {
return;
}
$data = themify_get_data();
if ( ! $new['remove_unused_css'] ) {
$data = $this->maybe_disable( $data );
}
if ( $new['remove_unused_css'] ) {
$data = $this->maybe_enable( $data );
}
themify_set_data( $data );
}
/**
* Maybe disable concate CSS.
*
* @param array $data Themify data.
*
* @return array
*/
protected function maybe_disable( array $data ): array {
if ( key_exists( 'setting-dev-mode-concate', $data ) && ! $data['setting-dev-mode-concate'] && key_exists( 'setting-dev-mode', $data ) && ! $data['setting-dev-mode'] ) {
return $data;
}
$data['setting-dev-mode-concate'] = false;
$data['setting-dev-mode'] = false;
return $data;
}
/**
* Maybe enable dev mode and concat.
*
* @param array $data Themify data.
*
* @return array
*/
protected function maybe_enable( array $data ): array {
if ( key_exists( 'setting-dev-mode-concate', $data ) && $data['setting-dev-mode-concate'] && key_exists( 'setting-dev-mode', $data ) && $data['setting-dev-mode'] ) {
return $data;
}
$data['setting-dev-mode'] = true;
$data['setting-dev-mode-concate'] = true;
return $data;
}
/**
* Enable the dev mode when RUCSS is activated.
*
* @param bool $is_enabled Is dev mode enabled.
* @return bool
*/
public function maybe_enable_dev_mode( $is_enabled ) {
if ( $this->options->get( 'remove_unused_css', false ) ) {
return true;
}
return $is_enabled;
}
}
@@ -0,0 +1,32 @@
<?php
namespace WP_Rocket\ThirdParty\Themes;
use WP_Theme;
use WP_Rocket\Event_Management\Subscriber_Interface;
abstract class ThirdpartyTheme implements Subscriber_Interface {
/**
* Name from the theme.
*
* @var string
*/
protected static $theme_name = '';
/**
* Check if the theme or one of its child theme is activated.
*
* @param WP_Theme $theme current theme.
* @return bool
*/
protected static function is_current_theme( $theme = null ): bool {
$theme = $theme instanceof WP_Theme ? $theme : wp_get_theme();
$template = $theme->get_template() ?? '';
if ( empty( $template ) ) {
return false;
}
return str_contains( strtolower( $template ), strtolower( static::$theme_name ) );
}
}
@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Themes;
class Uncode extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'uncode';
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [
'rocket_exclude_js' => 'exclude_js',
'rocket_excluded_inline_js_content' => 'exclude_inline_js',
'rocket_exclude_defer_js' => 'exclude_defer_js',
'rocket_delay_js_exclusions' => 'exclude_delay_js',
];
}
/**
* Excludes Uncode init and ai-uncode JS files from minification/combine
*
* @since 3.1
*
* @param array $excluded_js Array of JS filepaths to be excluded.
* @return array
*/
public function exclude_js( $excluded_js ): array {
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/init.min.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.min.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/ai-uncode.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/ai-uncode.min.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/ai-uncode.min.js' );
return $excluded_js;
}
/**
* Excludes some Uncode inline scripts from combine JS
*
* @since 3.1
*
* @param array $inline_js Array of patterns to match for exclusion.
* @return array
*/
public function exclude_inline_js( $inline_js ): array {
$inline_js[] = 'SiteParameters';
$inline_js[] = 'script-';
$inline_js[] = 'initBox';
$inline_js[] = 'initHeader';
$inline_js[] = 'fixMenuHeight';
return $inline_js;
}
/**
* Excludes Uncode JS files from defer JS
*
* @since 3.2.5
*
* @param array $exclude_defer_js Array of JS filepaths to be excluded.
* @return array
*/
public function exclude_defer_js( $exclude_defer_js ): array {
$exclude_defer_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.js' );
$exclude_defer_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/init.min.js' );
$exclude_defer_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.min.js' );
$exclude_defer_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/ai-uncode.min.js' );
$exclude_defer_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/ai-uncode.min.js' );
$exclude_defer_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/ai-uncode.js' );
return $exclude_defer_js;
}
/**
* Excludes Uncode JS files from delay JS
*
* @since 3.10.5
*
* @param array $exclude_delay_js Array of JS to be excluded.
* @return array
*/
public function exclude_delay_js( $exclude_delay_js ): array {
$exclude_delay_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.js' );
$exclude_delay_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/init.min.js' );
$exclude_delay_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.min.js' );
$exclude_delay_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/ai-uncode.min.js' );
$exclude_delay_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/ai-uncode.min.js' );
$exclude_delay_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/ai-uncode.js' );
$exclude_delay_js[] = 'UNCODE\.(.*)\)\;';
return $exclude_delay_js;
}
}
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Themes;
class Xstore extends ThirdpartyTheme {
/**
* Theme name
*
* @var string
*/
protected static $theme_name = 'xstore';
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! self::is_current_theme() ) {
return [];
}
return [ 'rocket_rucss_inline_content_exclusions' => 'exclude_inline_content' ];
}
/**
* Excludes the contents with patterns from being processed by RUCSS
*
* @param array $patterns Array of patterns to preserve.
*
* @return array
*/
public function exclude_inline_content( $patterns ): array {
$patterns[] = '.slider-';
$patterns[] = '.slider-item-';
return $patterns;
}
}