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,63 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Engine\Activation\ActivationInterface;
use WP_Rocket\Engine\Deactivation\DeactivationInterface;
use WP_Rocket\Event_Management\Event_Manager;
use WP_Rocket\Event_Management\Event_Manager_Aware_Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
abstract class AbstractNoCacheHost implements ActivationInterface, DeactivationInterface, Event_Manager_Aware_Subscriber_Interface {
use ReturnTypesTrait;
/**
* Event Manager instance
*
* @var Event_Manager
*/
protected $event_manager;
/**
* Actions to perform on plugin activation
*
* @since 3.6.3
*
* @return void
*/
public function activate() {
add_action( 'rocket_activation', [ $this, 'no_cache_config' ] );
}
/**
* Actions to perform on plugin deactivation
*
* @since 3.6.3
*
* @return void
*/
public function deactivate() {
add_action( 'rocket_deactivation', [ $this, 'no_cache_config' ] );
}
/**
* Prevent writing in advanced-cache.php & wp-config.php when on self-caching host.
*
* @since 3.6.3
*
* @return void
*/
public function no_cache_config() {
add_filter( 'rocket_set_wp_cache_constant', [ $this, 'return_false' ] );
add_filter( 'rocket_generate_advanced_cache_file', [ $this, 'return_false' ] );
}
/**
* Sets the event manager for the subscriber.
*
* @param Event_Manager $event_manager Event Manager instance.
*/
public function set_event_manager( Event_Manager $event_manager ) {
$this->event_manager = $event_manager;
}
}
@@ -0,0 +1,117 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\NullSubscriber;
/**
* Compatibility class for Cloudways Varnish
*
* @since 3.5.5
*/
class Cloudways extends NullSubscriber implements Subscriber_Interface {
/**
* Array of events this subscriber wants to listen to.
*
* @since 3.5.5
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_display_input_varnish_auto_purge' => 'return_false',
'do_rocket_varnish_http_purge' => 'should_purge',
'rocket_varnish_field_settings' => 'varnish_addon_title',
'rocket_varnish_ip' => 'varnish_ip',
];
}
/**
* Determine if the Varnish server is up and running.
*
* @since 3.6.1
*/
private static function is_varnish_running() {
if ( ! isset( $_SERVER['HTTP_X_VARNISH'] ) ) {
return false;
}
if ( ! isset( $_SERVER['HTTP_X_APPLICATION'] ) ) {
return false;
}
return ( 'varnishpass' !== trim( strtolower( $_SERVER['HTTP_X_APPLICATION'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
}
/**
* Returns false
*
* @since 3.5.5
*
* @return bool
*/
public function return_false() {
return false;
}
/**
* Returns should purge Varnish.
*
* @since 3.5.5
*
* @return true
*/
public function should_purge() {
return self::is_varnish_running();
}
/**
* Displays custom title for the Varnish add-on
*
* @since 3.5.5
*
* @param array $settings Array of settings for Varnish.
* @return array
*/
public function varnish_addon_title( array $settings ) {
if ( ! self::is_varnish_running() ) {
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Varnish auto-purge will be automatically enabled once Varnish is enabled on your %s server.', 'rocket' ),
'Cloudways'
);
return $settings;
}
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'Cloudways'
);
return $settings;
}
/**
* Adds Cloudways Varnish IP to varnish IPs array
*
* @since 3.5.5
*
* @param array $varnish_ip Varnish IP.
* @return array
*/
public function varnish_ip( $varnish_ip ) {
if ( ! self::is_varnish_running() ) {
return $varnish_ip;
}
if ( ! is_array( $varnish_ip ) ) {
$varnish_ip = (array) $varnish_ip;
}
$varnish_ip[] = '127.0.0.1:8080';
return $varnish_ip;
}
}
@@ -0,0 +1,112 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
/**
* Compatibility class for DreamPress
*
* @since 3.7.2
*/
class Dreampress extends AbstractNoCacheHost {
/**
* Array of events this subscriber wants to listen to.
*
* @since 3.7.2
*
* @return array
*/
public static function get_subscribed_events() {
return [
'do_rocket_varnish_http_purge' => 'return_true',
'rocket_varnish_field_settings' => 'set_varnish_addon_title',
'rocket_display_input_varnish_auto_purge' => 'return_false',
'rocket_varnish_ip' => 'set_varnish_host',
'rocket_set_wp_cache_constant' => 'return_false',
'do_rocket_generate_caching_files' => 'return_false',
'rocket_generate_advanced_cache_file' => 'return_false',
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
'rocket_htaccess_mod_expires' => [ 'remove_htaccess_html_expire', 5 ],
];
}
/**
* Changes the text on the Varnish one-click block.
*
* @since 3.7.2
*
* @param array $settings Field settings data.
*
* @return array modified field settings data.
*/
public function set_varnish_addon_title( $settings ) {
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'DreamPress'
);
return $settings;
}
/**
* Sets the Varnish host to localhost
*
* @since 3.7.2
*
* @param mixed $hosts Varnish hosts.
* @return array
*/
public function set_varnish_host( $hosts ) {
if ( ! is_array( $hosts ) ) {
$hosts = (array) $hosts;
}
if ( in_array( 'localhost', $hosts, true ) ) {
return $hosts;
}
$hosts[] = 'localhost';
return $hosts;
}
/**
* Remove expiration on HTML to prevent issue with Varnish cache.
*
* @since 3.7.2
*
* @param string $rules htaccess rules.
*
* @return string Updated htaccess rules.
*/
public function remove_htaccess_html_expire( $rules ) {
$rules = preg_replace( '@\s*#\s*Your document html@', '', $rules );
$rules = preg_replace( '@\s*ExpiresByType text/html\s*"access plus \d+ (seconds|minutes|hour|week|month|year)"@', '', $rules );
return $rules;
}
/**
* Performs these actions during the plugin activation
*
* @since 3.7.2
*
* @return void
*/
public function activate() {
parent::activate();
add_action( 'rocket_activation', [ $this, 'activate_no_htaccess_html_expire' ] );
}
/**
* Remove expiration on HTML on activation to prevent issue with Varnish cache.
*
* @since 3.7.2
*
* @return void
*/
public function activate_no_htaccess_html_expire() {
add_filter( 'rocket_htaccess_mod_expires', [ $this, 'remove_htaccess_html_expire' ] );
}
}
@@ -0,0 +1,192 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class Godaddy implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Godaddy vip url
*
* @var string
*/
private $vip_url = '';
/**
* Godaddy constructor.
*
* @param string $vip_url Godaddy vip url.
*/
public function __construct( $vip_url = '' ) {
$this->vip_url = method_exists( '\WPaas\Plugin', 'vip' ) ? \WPaas\Plugin::vip() : $vip_url;
}
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @see Subscriber_Interface.
*
* @since 3.9.1
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_varnish_field_settings' => 'varnish_field',
'rocket_display_input_varnish_auto_purge' => [ 'return_false' ],
'set_rocket_wp_cache_define' => [ 'return_true' ],
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
'rocket_htaccess_mod_rewrite' => [ 'return_false' ],
'rocket_htaccess_mod_expires' => [ 'remove_html_expire', 5 ],
'before_rocket_clean_domain' => 'clean_domain',
'before_rocket_clean_file' => 'clean_file',
'before_rocket_clean_home' => [ 'clean_home', 10, 2 ],
];
}
/**
* Changes the text on the Varnish one-click block.
*
* @since 3.9.1
*
* @param array $settings Field settings data.
*
* @return array modified field settings data.
*/
public function varnish_field( $settings ): array {
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'GoDaddy'
);
return $settings;
}
/**
* Remove expiration on HTML to prevent issue with Varnish cache.
*
* @since 3.9.1
*
* @param string $rules htaccess rules.
*
* @return string
*/
public function remove_html_expire( $rules ): string {
$rules = preg_replace( '@\s*#\s*Your document html@', '', $rules );
$rules = preg_replace( '@\s*ExpiresByType text/html\s*"access plus \d+ (seconds|minutes|hour|week|month|year)"@', '', $rules );
return $rules;
}
/**
* Call the Varnish server to purge the cache with GoDaddy.
*
* @since 3.9.1
*
* @return void
*/
public function clean_domain() {
$this->purge_request( 'BAN' );
}
/**
* Call the Varnish server to purge a specific URL with GoDaddy.
*
* @since 3.9.1
*
* @param string $url URL to purge.
*
* @return void
*/
public function clean_file( $url ) {
$this->purge_request( 'BAN', $url );
}
/**
* Call the Varnish server to purge the home with GoDaddy.
*
* @since 3.9.1
*
* @param string $root root URL.
* @param string $lang language code.
*
* @return void
*/
public function clean_home( $root, $lang ) {
$home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
$home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base );
$this->purge_request( 'BAN', $home_url );
$this->purge_request( 'BAN', $home_pagination_url );
}
/**
* Perform the call to the Varnish server to purge
*
* @since 3.9.1
* @source WPaaS\Cache
*
* @param string $method can be BAN or PURGE.
* @param string $url URL to purge.
*
* @return void
*/
private function purge_request( string $method, string $url = '' ) {
if ( empty( $this->vip_url ) ) {
return;
}
if ( empty( $url ) ) {
$url = home_url();
}
$host = wp_parse_url( $url, PHP_URL_HOST );
$url = untrailingslashit( set_url_scheme( str_replace( $host, $this->vip_url, $url ), 'http' ) );
wp_cache_flush();
// This forces the APC cache to flush across the server.
update_option( 'gd_system_last_cache_flush', time() );
wp_remote_request(
esc_url_raw( $url ),
[
'method' => $method,
'blocking' => false,
'headers' => [
'Host' => $host,
],
]
);
}
/**
* Performs these actions during the plugin activation
*
* @since 3.9.1
*
* @return void
*/
public function activate() {
add_action( 'rocket_activation', [ $this, 'activate_no_htaccess_html_expire' ] );
}
/**
* Remove expiration on HTML on activation to prevent issue with Varnish cache.
*
* @since 3.9.1
*
* @return void
*/
public function activate_no_htaccess_html_expire() {
add_filter( 'rocket_htaccess_mod_expires', [ $this, 'remove_htaccess_html_expire' ] );
}
}
@@ -0,0 +1,151 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
/**
* Host Resolver.
*
* @since 3.6.3
*/
class HostResolver {
/**
* Name of the current host service.
*
* @var string
*/
private static $hostname = '';
/**
* Get the name of an identifiable hosting service.
*
* @since 3.6.3
*
* @param bool $ignore_cached_hostname (optional) Don't use cached hostname when true.
*
* @return string Name of the hosting service or '' if no service is recognized.
*/
public static function get_host_service( $ignore_cached_hostname = false ) {
if ( ! $ignore_cached_hostname && ! empty( self::$hostname ) ) {
return self::$hostname;
}
if ( isset( $_SERVER['GROUPONE_BRAND_NAME'] ) ) {
$group_one_brand_name = strtolower( sanitize_text_field( wp_unslash( $_SERVER['GROUPONE_BRAND_NAME'] ) ) );
switch ( $group_one_brand_name ) {
case 'one.com':
self::$hostname = 'onecom';
return 'onecom';
case 'proisp.no':
self::$hostname = 'proisp';
return 'proisp';
}
}
if ( isset( $_SERVER['cw_allowed_ip'] ) ) {
self::$hostname = 'cloudways';
return 'cloudways';
}
if ( rocket_get_constant( 'IS_PRESSABLE' ) ) {
self::$hostname = 'pressable';
return 'pressable';
}
if ( getenv( 'SPINUPWP_CACHE_PATH' ) ) {
self::$hostname = 'spinupwp';
return 'spinupwp';
}
if (
(
class_exists( 'WpeCommon' )
&&
function_exists( 'wpe_param' )
)
) {
self::$hostname = 'wpengine';
return 'wpengine';
}
if ( rocket_has_constant( 'O2SWITCH_VARNISH_PURGE_KEY' ) ) {
self::$hostname = 'o2switch';
return 'o2switch';
}
if ( rocket_get_constant( 'WPCOMSH_VERSION' ) ) {
self::$hostname = 'wordpresscom';
return 'wordpresscom';
}
if (
rocket_get_constant( '\Savvii\CacheFlusherPlugin::NAME_FLUSH_NOW' )
&&
rocket_get_constant( '\Savvii\CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW' )
) {
return 'savvii';
}
if ( self::is_dreampress() ) {
return 'dreampress';
}
if ( isset( $_SERVER['HTTP_WPXCLOUD'] ) ) {
self::$hostname = 'wpxcloud';
return 'wpxcloud';
}
if ( isset( $_SERVER['X-LSCACHE'] ) ) {
self::$hostname = 'litespeed';
return 'litespeed';
}
if ( class_exists( '\WPaas\Plugin' ) ) {
self::$hostname = 'godaddy';
return 'godaddy';
}
if ( isset( $_SERVER['KINSTA_CACHE_ZONE'] ) ) {
self::$hostname = 'kinsta';
return 'kinsta';
}
if ( defined( 'WP_NINUKIS_WP_NAME' ) || class_exists( 'NinukisCaching' ) ) {
self::$hostname = 'pressidium';
return self::$hostname;
}
return '';
}
/**
* Checks if the current host is DreamPress
*
* @since 3.7.2
*
* @return boolean
*/
private static function is_dreampress() {
if ( ! isset( $_SERVER['DH_USER'] ) ) {
return false;
}
if (
! rocket_get_constant( 'WP_ROCKET_IS_TESTING', false )
&&
'dp-' !== substr( gethostname(), 0, 3 )
) {
return false;
}
return 'wp_' === substr( sanitize_key( wp_unslash( $_SERVER['DH_USER'] ) ), 0, 3 );
}
}
@@ -0,0 +1,60 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\NullSubscriber;
use WP_Rocket\ThirdParty\SubscriberFactoryInterface;
/**
* Host Subscriber Factory
*
* @since 3.6.3
*/
class HostSubscriberFactory implements SubscriberFactoryInterface {
/**
* Get a Subscriber Interface object.
*
* @since 3.6.3
*
* @return Subscriber_Interface A Subscribe Interface for the current host.
*/
public function get_subscriber() {
$host_service = HostResolver::get_host_service( rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) );
switch ( $host_service ) {
case 'pressable':
return new Pressable();
case 'cloudways':
return new Cloudways();
case 'spinupwp':
return new SpinUpWP();
case 'wpengine':
return new WPEngine();
case 'o2switch':
return new O2Switch();
case 'wordpresscom':
return new WordPressCom();
case 'savvii':
return new Savvii();
case 'dreampress':
return new Dreampress();
case 'wpxcloud':
return new WPXCloud();
case 'litespeed':
return new LiteSpeed();
case 'godaddy':
return new Godaddy();
case 'kinsta':
return new Kinsta();
case 'onecom':
return new OneCom();
case 'proisp':
return new ProIsp();
case 'pressidium':
return new Pressidium();
default:
return new NullSubscriber();
}
}
}
@@ -0,0 +1,163 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class Kinsta implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Subscribed events for Kinsta.
*
* @inheritDoc
*/
public static function get_subscribed_events() {
global $kinsta_cache;
$events = [
'do_rocket_generate_caching_files' => [ 'return_false', PHP_INT_MAX ],
'rocket_display_varnish_options_tab' => 'return_false',
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
];
if ( isset( $kinsta_cache ) ) {
$events['after_rocket_clean_domain'] = 'clean_kinsta_cache';
$events['after_rocket_clean_post'] = 'clean_kinsta_post_cache';
$events['rocket_rucss_after_clearing_usedcss'] = 'clean_kinsta_cache_url';
$events['rocket_rucss_complete_job_status'] = 'clean_kinsta_cache_url';
$events['after_rocket_clean_home'] = [ 'clean_kinsta_cache_home', 10, 2 ];
$events['after_rocket_clean_file'] = 'clean_kinsta_cache_url';
$events['wp_rocket_loaded'] = 'remove_partial_purge_hooks';
return $events;
}
$events['admin_notices'] = 'display_error_notice';
return $events;
}
/**
* Clear Kinsta cache when clearing WP Rocket cache
*
* @since 3.0
*
* @return void
*/
public function clean_kinsta_cache() {
global $kinsta_cache;
if ( ! empty( $kinsta_cache->kinsta_cache_purge ) ) {
$kinsta_cache->kinsta_cache_purge->purge_complete_caches();
}
}
/**
* Partially clear Kinsta cache when partially clearing WP Rocket cache
*
* @since 3.0
*
* @param object $post Post object.
* @return void
*/
public function clean_kinsta_post_cache( $post ) {
global $kinsta_cache;
$kinsta_cache->kinsta_cache_purge->initiate_purge( $post->ID, 'post' );
}
/**
* Clears Kinsta cache for the homepage URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.0.4
*
* @param string $root WP Rocket root cache path.
* @param string $lang Current language.
* @return void
*/
public function clean_kinsta_cache_home( $root = '', $lang = '' ) {
$url = get_rocket_i18n_home_url( $lang );
$url = trailingslashit( $url ) . 'kinsta-clear-cache/';
wp_safe_remote_get(
$url,
[
'blocking' => false,
'timeout' => 0.01,
]
);
}
/**
* Clears Kinsta cache for a specific URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.0.4
*
* @param string $url URL to purge.
* @return void
*/
public function clean_kinsta_cache_url( $url ) {
$url = trailingslashit( $url ) . 'kinsta-clear-cache/';
wp_safe_remote_get(
$url,
[
'blocking' => false,
'timeout' => 0.01,
]
);
}
/**
* Remove WP Rocket functions on WP core action hooks to prevent triggering a double cache clear.
*
* @since 3.0
*
* @return void
*/
public function remove_partial_purge_hooks() {
// WP core action hooks clean_post() gets hooked into.
$clean_post_hooks = [
// Disables the refreshing of partial cache when content is edited.
'wp_trash_post',
'delete_post',
'clean_post_cache',
'wp_update_comment_count',
];
// Remove rocket_clean_post() from core action hooks.
array_map(
function ( $hook ) {
remove_action( $hook, 'rocket_clean_post' );
},
$clean_post_hooks
);
remove_filter( 'rocket_clean_files', 'rocket_clean_files_users' );
}
/**
* Display notice when we are on Kinsta but the plugin is not present.
*
* @return void
*/
public function display_error_notice() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$screen = get_current_screen();
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
// translators: %1$s = opening link tag, %2$s = closing link tag.
'message' => sprintf( __( 'Your installation seems to be missing core Kinsta files managing Cache clearing, which will prevent your Kinsta installation and WP Rocket from working correctly. Please get in touch with Kinsta support through your %1$sMyKinsta%2$s account to resolve this issue.', 'rocket' ), '<a href="https://my.kinsta.com/login/" target="_blank">', '</a>' ),
]
);
}
}
@@ -0,0 +1,153 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
class LiteSpeed implements Subscriber_Interface {
/**
* Litespeed headers
*
* @var array
*/
private $headers = [];
/**
* Subscribed events for Litespeed.
*
* @since 3.9.2
* @inheritDoc
*/
public static function get_subscribed_events() {
return [
'before_rocket_clean_domain' => 'litespeed_clean_domain',
'before_rocket_clean_file' => 'litespeed_clean_file',
'before_rocket_clean_home' => [ 'litespeed_clean_home', 10, 2 ],
];
}
/**
* Add purge headers to the request
*
* @since 3.9.2
*
* @return void
*/
public function litespeed_send_headers() {
if ( empty( $this->headers ) ) {
return;
}
foreach ( $this->headers as $header ) {
@header( "X-LiteSpeed-Purge: {$header}", false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
}
}
/**
* Purge all pages in LiteSpeed
*
* @since 3.9.2
*
* @return void
*/
public function litespeed_clean_domain() {
$this->litespeed_header_purge_all();
}
/**
* Purge a specific page
*
* @since 3.9.2
*
* @param string $url The url to purge.
*
* @return void
*/
public function litespeed_clean_file( $url ) {
$this->litespeed_header_purge_url( trailingslashit( $url ) );
}
/**
* Purge the homepage and its pagination
*
* @since 3.9.2
*
* @param string $root The path of home cache file.
* @param string $lang The current lang to purge.
*
* @return void
*/
public function litespeed_clean_home( $root, $lang ) {
$home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
$urls = [
'home' => trailingslashit( get_rocket_i18n_home_url( $lang ) ),
'pagination' => $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base ),
];
array_walk(
$urls,
function ( &$url ) {
$url = wp_parse_url( $url, PHP_URL_PATH );
}
);
$urls = array_filter( $urls );
if ( empty( $urls ) ) {
return;
}
$this->send_header( 'X-LiteSpeed-Purge: ' . $urls['home'] );
$this->send_header( 'X-LiteSpeed-Purge: ' . $urls['pagination'] );
}
/**
* Set LiteSpeed header for the URL to purge
*
* @since 3.9.2
*
* @param string $url The URL to purge.
*
* @return void
*/
private function litespeed_header_purge_url( $url ) {
$path = wp_parse_url( $url, PHP_URL_PATH );
if ( ! $path ) {
return;
}
$header = 'X-LiteSpeed-Purge: ' . $path;
$this->send_header( $header );
}
/**
* Set LiteSpeed header to purge all
*
* @since 3.9.2
*
* @return void
*/
private function litespeed_header_purge_all() {
$this->send_header( 'X-LiteSpeed-Purge: *', true );
}
/**
* If header is not in header_list() send it
*
* @since 3.9.2
*
* @param string $header To be sent.
* @param boolean $replace header.
*
* @return void
*/
private function send_header( $header, $replace = false ) {
if ( headers_sent() || in_array( $header, headers_list(), true ) ) {
return;
}
$this->headers[] = $header;
@header( $header, $replace ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
}
}
@@ -0,0 +1,126 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Engine\Activation\ActivationInterface;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\NullSubscriber;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
/**
* Compatibility class for O2Switch
*
* @since 3.6.3
*/
class O2Switch extends NullSubscriber implements Subscriber_Interface, ActivationInterface {
use ReturnTypesTrait;
/**
* Array of events this subscriber wants to listen to.
*
* @since 3.6.3
*
* @return array
*/
public static function get_subscribed_events() {
return [
'do_rocket_varnish_http_purge' => 'return_true',
'rocket_varnish_field_settings' => 'varnish_addon_title',
'rocket_display_input_varnish_auto_purge' => 'return_false',
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
'rocket_htaccess_mod_expires' => [ 'remove_htaccess_html_expire', 5 ],
'rocket_varnish_purge_headers' => 'add_purge_headers',
'rocket_varnish_purge_url' => [ 'remove_regex_from_purge_url', 10, 2 ],
];
}
/**
* Changes the text on the Varnish one-click block.
*
* @since 3.6.3
*
* @param array $settings Field settings data.
*
* @return array modified field settings data.
*/
public function varnish_addon_title( $settings ) {
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'O2Switch'
);
return $settings;
}
/**
* Remove expiration on HTML to prevent issue with Varnish cache.
*
* @since 3.6.3
*
* @param string $rules htaccess rules.
*
* @return string Updated htaccess rules.
*/
public function remove_htaccess_html_expire( $rules ) {
$rules = preg_replace( '@\s*#\s*Your document html@', '', $rules );
$rules = preg_replace( '@\s*ExpiresByType text/html\s*"access plus \d+ (seconds|minutes|hour|week|month|year)"@', '', $rules );
return $rules;
}
/**
* Adjust purge request header array.
*
* @since 3.6.3
*
* @param array $headers Headers to send.
*
* @return array Array for headers to be sent.
*/
public function add_purge_headers( $headers ) {
$headers['X-VC-Purge-Key'] = rocket_get_constant( 'O2SWITCH_VARNISH_PURGE_KEY' );
if ( isset( $headers['X-Purge-Method'] ) && 'regex' === $headers['X-Purge-Method'] ) {
$headers['X-Purge-Regex'] = '.*';
unset( $headers['X-Purge-Method'] );
}
return $headers;
}
/**
* Remove regex part from purge_url as it's handled via headers instead.
*
* @since 3.6.3
*
* @param string $full_purge_url Full url for purge, regex included.
* @param string $main_purge_url Main url without regex.
*
* @return mixed
*/
public function remove_regex_from_purge_url( $full_purge_url, $main_purge_url ) {
return $main_purge_url;
}
/**
* Performs these actions during the plugin activation
*
* @return void
*/
public function activate() {
add_action( 'rocket_activation', [ $this, 'activate_no_htaccess_html_expire' ] );
}
/**
* Remove expiration on HTML on activation to prevent issue with Varnish cache.
*
* @since 3.6.3
*
* @return void
*/
public function activate_no_htaccess_html_expire() {
add_filter( 'rocket_htaccess_mod_expires', [ $this, 'remove_htaccess_html_expire' ] );
}
}
@@ -0,0 +1,170 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
/**
* Subscriber for compatibility with One.com hosting.
*
* @since 3.12.1
*/
class OneCom implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Array of events this subscriber wants to listen to.
*
* @since 3.6.3
*
* @return array
*/
public static function get_subscribed_events() {
return [
'pre_get_rocket_option_cdn' => 'maybe_enable_cdn_option',
'pre_get_rocket_option_cdn_cnames' => 'maybe_update_cdn_cname',
'pre_get_rocket_option_cdn_zone' => 'maybe_update_cdn_zone',
'rocket_cdn_reject_files' => 'exclude_from_cdn',
'rocket_disable_cdn_option_change' => 'is_oc_cdn_enabled',
'rocket_cdn_settings_fields' => 'disable_cdn_change',
'do_rocket_varnish_http_purge' => 'is_varnish_active',
'rocket_varnish_field_settings' => 'maybe_set_varnish_addon_title',
'rocket_display_input_varnish_auto_purge' => 'should_display_varnish_auto_purge_input',
'rocket_display_rocketcdn_cta' => 'return_false',
'rocket_display_rocketcdn_status' => 'return_false',
'rocket_promote_rocketcdn_notice' => 'return_false',
];
}
/**
* Check if one.com cdn is enabled.
*
* @return boolean
*/
public function is_oc_cdn_enabled(): bool {
return rocket_get_constant( 'vcaching', false ) && rest_sanitize_boolean( get_option( 'oc_cdn_enabled' ) );
}
/**
* Enable CDN option.
*
* @param string|null $cdn CDN Option.
* @return bool|null
*/
public function maybe_enable_cdn_option( ?string $cdn ) {
return $this->is_oc_cdn_enabled() ? true : $cdn;
}
/**
* Update CNAME
*
* @param string|null $cname CDN CNAME.
* @return array|null
*/
public function maybe_update_cdn_cname( ?string $cname ) {
return $this->is_oc_cdn_enabled() ? [ $this->build_cname() ] : $cname;
}
/**
* Update CDN Zones.
*
* @param string|null $zone CDN ZONES.
* @return array|null
*/
public function maybe_update_cdn_zone( ?string $zone ) {
return $this->is_oc_cdn_enabled() ? [ 'all' ] : $zone;
}
/**
* Exclude files from being rewritten.
* From 3.12.5.2 we are excluding new wp-content directory paths if it's not the normal one.
*
* @param array $files Array of files to be excluded.
* @return array
*/
public function exclude_from_cdn( array $files ): array {
if ( ! $this->is_oc_cdn_enabled() ) {
return $files;
}
$files[] = '/wp-includes/(.*)';
return $files;
}
/**
* Disable CDN option change.
*
* @param array $settings CDN field settings data.
* @return array
*/
public function disable_cdn_change( array $settings ): array {
if ( ! $this->is_oc_cdn_enabled() ) {
return $settings;
}
$settings['cdn']['container_class'][] = 'wpr-isDisabled';
$settings['cdn']['input_attr']['disabled'] = 1;
return $settings;
}
/**
* Purge varnish cache.
*
* @return boolean
*/
public function should_display_varnish_auto_purge_input(): bool {
return ! $this->is_varnish_active();
}
/**
* Set varnish addon title
*
* @param array $settings Varnish settings field data.
* @return array
*/
public function maybe_set_varnish_addon_title( array $settings ): array {
// Bail out if varnish is disabled.
if ( ! $this->is_varnish_active() ) {
return $settings;
}
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'One.com'
);
return $settings;
}
/**
* Check if varnish option is enabled.
*
* @return boolean
*/
public function is_varnish_active() {
return rocket_get_constant( 'vcaching', false ) && rest_sanitize_boolean( get_option( 'varnish_caching_enable' ) );
}
/**
* Build CDN CNAME.
*
* @return string
*/
public function build_cname(): string {
if ( ! isset( $_SERVER['ONECOM_DOMAIN_NAME'] ) && ! isset( $_SERVER['HTTP_HOST'] ) ) {
return '';
}
$domain_name = sanitize_text_field( wp_unslash( $_SERVER['ONECOM_DOMAIN_NAME'] ) );
$http_host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
$is_subdomain = '' === str_replace( $domain_name, '', $http_host ) ? false : true;
return $is_subdomain ? "usercontent.one/wp/$http_host" : "usercontent.one/wp/www.$http_host";
}
}
@@ -0,0 +1,70 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
/**
* Subscriber for compatibility with Pressable hosting
*
* @since 3.3
*/
class Pressable extends AbstractNoCacheHost {
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.3
*
* @return array
*/
public static function get_subscribed_events() {
return [
'do_rocket_generate_caching_files' => [ 'return_false', PHP_INT_MAX ],
'rocket_display_varnish_options_tab' => 'return_false',
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
'after_rocket_clean_domain' => 'purge_pressable_cache',
'rocket_url_to_path' => 'fix_wp_includes_path',
'rocket_set_wp_cache_constant' => 'return_false',
'rocket_generate_advanced_cache_file' => 'return_false',
'rocket_cdn_cnames' => [ 'add_pressable_cdn_cname', 1 ],
];
}
/**
* Purge Pressable cache
*
* @since 3.3
*
* @return void
*/
public function purge_pressable_cache() {
wp_cache_flush();
}
/**
* Modify wp-includes absolute path to be able to optimize assets in this directory on Pressable
*
* @since 3.3
*
* @param string $file Absolute path to the file.
* @return string
*/
public function fix_wp_includes_path( $file ) {
return preg_replace( '#^(.+)(wp-includes(?:.+))$#is', ABSPATH . '$2', $file );
}
/**
* Add Pressable CDN cname to WP Rocket list to recognize assets as internal ones.
*
* @since 3.3
*
* @param array $hosts Array of CDN URLs.
* @return array
*/
public function add_pressable_cdn_cname( $hosts ) {
if ( ! rocket_get_constant( 'WP_STACK_CDN_DOMAIN' ) ) {
return $hosts;
}
$hosts[] = WP_STACK_CDN_DOMAIN;
return $hosts;
}
}
@@ -0,0 +1,137 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use NinukisCaching;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class Pressidium extends AbstractNoCacheHost {
use ReturnTypesTrait;
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @see Subscriber_Interface.
*
* @return array
*/
public static function get_subscribed_events() {
$events = [];
if ( defined( 'WP_NINUKIS_WP_NAME' ) ) {
$events['rocket_varnish_field_settings'] = 'pressidium_varnish_field';
$events['rocket_display_input_varnish_auto_purge'] = 'return_false';
$events['rocket_cache_mandatory_cookies'] = [ 'return_empty_array', PHP_INT_MAX ];
$events['admin_init'] = 'clear_cache_after_pressidium';
}
if ( class_exists( 'NinukisCaching' ) ) {
$events['after_rocket_clean_domain'] = 'clean_pressidium';
$events['after_rocket_clean_file'] = [ 'purge_url', 10, 1 ];
$events['after_rocket_clean_post'] = [ 'clean_post', 10, 2 ];
}
return $events;
}
/**
* Changes the text on the Varnish one-click block.
*
* @since 3.0
* @author Remy Perona
*
* @param array $settings Field settings data.
*
* @return array modified field settings data.
*/
public function pressidium_varnish_field( $settings ) {
// Translators: %s = Hosting name.
$settings['varnish_auto_purge']['title'] = sprintf( __( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ), 'Pressidium' );
return $settings;
}
/**
* Clear WP Rocket cache after purged the Varnish cache via Pressidium Hosting
*
* @since 2.5.11
*
* @return void
*/
public function clear_cache_after_pressidium() {
if ( isset( $_POST['purge-all'] ) && current_user_can( 'manage_options' ) && check_admin_referer( WP_NINUKIS_WP_NAME . '-caching' ) ) {
// Clear all caching files.
rocket_clean_domain();
}
}
/**
* Call the cache server to purge the cache with Pressidium hosting.
*
* @since 2.6
*
* @return void
*/
public function clean_pressidium() {
$plugin = NinukisCaching::get_instance();
$plugin->purgeAllCaches();
}
/**
* Returns the path of URLs.
*
* @param array|string $urls Urls we want to get paths.
* @return array|void the path.
*/
private function get_paths( $urls ) {
if ( ! is_array( $urls ) ) {
$urls = (array) $urls;
}
$paths = [];
foreach ( $urls as $url ) {
$parsed_url = get_rocket_parse_url( $url );
$paths[] = $parsed_url['path'];
}
return $paths;
}
/**
* Purge the cache of Pressidium from paths.
*
* @param array $paths Paths of pages we are going to purge cache.
*
* @return void
*/
private function purge_cache( $paths ) {
NinukisCaching::get_instance()->purge_cache( $paths );
}
/**
* Purge the cache for the given URL.
*
* @param string|array $url URL we want to purge.
*
* @return void
*/
public function purge_url( $url ) {
$paths = $this->get_paths( $url );
$this->purge_cache( $paths );
}
/**
* Clean cache of post.
*
* @param WP_Post $post Post that need to be cleaned.
* @param array $purge_urls URLs that need to be purged.
*
* @return void
*/
public function clean_post( $post, $purge_urls ) {
// Purge related urls.
$paths = $this->get_paths( $purge_urls );
$this->purge_cache( $paths );
}
}
@@ -0,0 +1,66 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with PRO ISP hosting.
*
* @since 3.13.1
*/
class ProIsp implements Subscriber_Interface {
/**
* Array of events this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'do_rocket_varnish_http_purge' => 'is_varnish_active',
'rocket_varnish_field_settings' => 'maybe_set_varnish_addon_title',
'rocket_display_input_varnish_auto_purge' => 'should_display_varnish_auto_purge_input',
];
}
/**
* Purge varnish cache.
*
* @return boolean
*/
public function should_display_varnish_auto_purge_input(): bool {
return ! $this->is_varnish_active();
}
/**
* Set varnish addon title
*
* @param array $settings Varnish settings field data.
* @return array
*/
public function maybe_set_varnish_addon_title( array $settings ): array {
// Bail out if varnish is disabled.
if ( ! $this->is_varnish_active() ) {
return $settings;
}
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'PRO ISP'
);
return $settings;
}
/**
* Check if varnish option is enabled.
*
* @return boolean
*/
public function is_varnish_active() {
return rocket_get_constant( 'vcaching', false ) && rest_sanitize_boolean( get_option( 'varnish_caching_enable' ) );
}
}
@@ -0,0 +1,101 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use Savvii\CacheFlusherPlugin;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
/**
* Compatibility for Savvii.
*
* @since 3.6.3
*/
class Savvii implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @see Subscriber_Interface.
*
* @since 3.6.3
*
* @return array
*/
public static function get_subscribed_events() {
return [
'do_rocket_generate_caching_files' => [ 'return_false', PHP_INT_MAX ],
'rocket_varnish_field_settings' => 'varnish_addon_title',
'rocket_display_input_varnish_auto_purge' => 'return_false',
'rocket_cache_mandatory_cookies' => 'return_empty_array',
'init' => 'clear_cache_after_savvii',
'after_rocket_clean_domain' => 'clean_savvii',
];
}
/**
* Changes the text on the Varnish one-click block.
*
* @since 3.6.3 Rename and move to new architecture.
* @since 3.0
*
* @param array $settings Field settings data.
*
* @return array modified field settings data.
*/
public function varnish_addon_title( $settings ) {
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'Savvii'
);
return $settings;
}
/**
* Clear WP Rocket cache after purged the Varnish cache via Savvii Hosting.
*
* @since 3.6.3 Rename and move to new architecture. Refactor. Fix wrong nonce names/actions.
* @since 2.6.5
*/
public function clear_cache_after_savvii() {
if (
! (
isset( $_REQUEST[ CacheFlusherPlugin::NAME_FLUSH_NOW ] )
&&
check_admin_referer( CacheFlusherPlugin::NAME_FLUSH_NOW )
)
&&
! (
isset( $_REQUEST[ CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW ] )
&&
check_admin_referer( CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW )
)
) {
return;
}
if ( ! current_user_can( 'rocket_purge_cache' ) ) {
return;
}
// Clear all caching files.
rocket_clean_domain();
// Preload cache.
run_rocket_bot();
run_rocket_sitemap_preload();
}
/**
* Call the cache server to purge the cache with Savvii hosting.
*
* @since 3.6.3 Rename and move to new architecture.
* @since 2.6.5
*/
public function clean_savvii() {
do_action( 'warpdrive_domain_flush' ); //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
}
}
@@ -0,0 +1,52 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\BootableServiceProviderInterface;
use WP_Rocket\ThirdParty\Hostings\HostResolver;
use WP_Rocket\ThirdParty\Hostings\HostSubscriberFactory;
/**
* Hostings compatibility service provider
*
* @since 3.6.3
*/
class ServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface {
/**
* Services provided
*
* @var array
*/
protected $provides = [];
/**
* Register the service in the provider array
*
* @return void
*/
public function boot() {
$hosting_service = HostResolver::get_host_service();
if ( ! empty( $hosting_service ) ) {
$this->provides[] = $hosting_service;
}
}
/**
* Registers the current hosting subscriber in the container
*
* @since 3.6.3
*
* @return void
*/
public function register() {
$hosting_service = HostResolver::get_host_service();
if ( ! empty( $hosting_service ) ) {
$this->getContainer()
->share( $hosting_service, ( new HostSubscriberFactory() )->get_subscriber() )
->addTag( 'hosting_subscriber' );
}
}
}
@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\{NullSubscriber, ReturnTypesTrait};
/**
* Compatibility class for SpinUpWP
*
* @since 3.6.2
*/
class SpinUpWP extends NullSubscriber implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Array of events this subscriber wants to listen to.
*
* @since 3.6.2
*
* @return array
*/
public static function get_subscribed_events() {
return [
'do_rocket_generate_caching_files' => 'return_false',
'rocket_display_varnish_options_tab' => 'return_false',
'rocket_cache_mandatory_cookies' => 'return_empty_array',
'after_rocket_clean_domain' => 'purge_site',
'wp_rocket_loaded' => 'remove_actions',
'after_rocket_clean_file' => 'purge_url',
'rocket_rucss_after_clearing_usedcss' => 'purge_url',
'rocket_rucss_complete_job_status' => 'purge_url',
'after_rocket_clean_term' => [ 'purge_term_urls', 10, 2 ],
'rocket_after_clean_terms' => 'purge_urls',
];
}
/**
* Purge SpinUpWP cache after clean domain.
*
* @since 3.6.2
*
* @return void
*/
public function purge_site() {
if ( ! function_exists( 'spinupwp_purge_site' ) ) {
return;
}
spinupwp_purge_site();
}
/**
* Remove rocket_clean_domain which prevents a double clear of the cache.
*
* @since 3.6.2
*
* @return void
*/
public function remove_actions() {
remove_action( 'switch_theme', 'rocket_clean_domain' );
}
/**
* Purge URL in SpinUpWP
*
* @param string $url URL.
*
* @return void
*/
public function purge_url( $url ) {
if ( ! function_exists( 'spinupwp_purge_url' ) ) {
return;
}
spinupwp_purge_url( trailingslashit( $url ) );
}
/**
* Purge multiple URLs
*
* @param array $urls Array of URLs.
*
* @return void
*/
public function purge_urls( $urls ) {
foreach ( $urls as $url ) {
$this->purge_url( $url );
}
}
/**
* Purge URLs related to a term
*
* @param WP_Term $term The term object.
* @param array $urls Array of URLs.
*
* @return void
*/
public function purge_term_urls( $term, $urls ) {
$this->purge_urls( $urls );
}
}
@@ -0,0 +1,117 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WpeCommon;
/**
* Compatibility class for WP Engine.
*
* @since 3.6.1
*/
class WPEngine extends AbstractNoCacheHost {
/**
* Array of events this subscriber wants to listen to.
*
* @since 3.6.1
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_varnish_field_settings' => 'varnish_addon_title',
'rocket_display_input_varnish_auto_purge' => 'return_false',
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
'admin_init' => 'run_rocket_bot_after_wpengine',
'rocket_set_wp_cache_constant' => 'return_false',
'do_rocket_generate_caching_files' => 'return_false',
'after_rocket_clean_domain' => 'clean_wpengine',
'rocket_buffer' => [ 'add_footprint', 50 ],
'rocket_disable_htaccess' => 'return_true',
'rocket_generate_advanced_cache_file' => 'return_false',
];
}
/**
* Changes the text on the Varnish one-click block.
*
* @since 3.6.1
*
* @param array $settings Field settings data.
*
* @return array modified field settings data.
*/
public function varnish_addon_title( $settings ) {
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'WP Engine'
);
return $settings;
}
/**
* Run WP Rocket preload bot after purged the Varnish cache via WP Engine Hosting.
*
* @since 3.6.1
*/
public function run_rocket_bot_after_wpengine() {
if ( ! wpe_param( 'purge-all' ) ) {
return;
}
if ( ! rocket_has_constant( 'PWP_NAME' ) ) {
return;
}
if ( ! check_admin_referer( rocket_get_constant( 'PWP_NAME' ) . '-config' ) ) {
return;
}
if ( ! current_user_can( 'rocket_preload_cache' ) ) {
return;
}
// Preload cache.
run_rocket_bot();
run_rocket_sitemap_preload();
}
/**
* Call the cache server to purge the cache with WP Engine hosting.
*
* @since 3.6.1
*/
public function clean_wpengine() {
if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) {
WpeCommon::purge_memcached();
}
if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) {
WpeCommon::purge_varnish_cache();
}
}
/**
* Add WP Rocket footprint on Buffer.
*
* @since 3.6.1
*
* @param string $buffer HTML content.
*
* @return string HTML with WP Rocket footprint.
*/
public function add_footprint( $buffer ) {
if ( ! preg_match( '/<\/html>/i', $buffer ) ) {
return $buffer;
}
$footprint = rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_FOOTPRINT' )
? "\n" . '<!-- Optimized for great performance'
: "\n" . '<!-- This website is like a Rocket, isn\'t it? Performance optimized by ' . rocket_get_constant( 'WP_ROCKET_PLUGIN_NAME' ) . '. Learn more: https://wp-rocket.me';
$footprint .= ' -->';
return $buffer . $footprint;
}
}
@@ -0,0 +1,90 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
/**
* Compatibility class for WPX Cloud.
*/
class WPXCloud extends AbstractNoCacheHost {
/**
* Array of events this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_varnish_ip' => 'varnish_ip',
'rocket_display_input_varnish_auto_purge' => 'return_false',
'do_rocket_varnish_http_purge' => 'return_true',
'rocket_varnish_field_settings' => 'varnish_addon_title',
'after_rocket_htaccess_rules' => 'append_cache_control_header',
];
}
/**
* Adds WPX Cloud Varnish IP to varnish IPs array
*
* @param array $varnish_ip Varnish IP.
* @return array
*/
public function varnish_ip( $varnish_ip ) {
if ( ! is_array( $varnish_ip ) ) {
$varnish_ip = (array) $varnish_ip;
}
$varnish_ip[] = '127.0.0.1:6081';
return $varnish_ip;
}
/**
* Displays custom title for the Varnish add-on
*
* @param array $settings Array of settings for Varnish.
* @return array
*/
public function varnish_addon_title( array $settings ) {
$settings['varnish_auto_purge']['title'] = sprintf(
// Translators: %s = Hosting name.
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
'WPX'
);
return $settings;
}
/**
* Append cache control header.
*
* @return string
*/
public function append_cache_control_header(): string {
$header = '<IfModule mod_headers.c>' . PHP_EOL;
$header .= 'Header append Cache-Control " s-maxage=3600, stale-while-revalidate=21600" "expr=%{CONTENT_TYPE} =~ m#text/html#"' . PHP_EOL;
$header .= '</IfModule>' . PHP_EOL;
return $header;
}
/**
* Performs these actions during the plugin activation.
*
* @return void
*/
public function activate() {
parent::activate();
add_action( 'rocket_activation', [ $this, 'append_cache_control_header_on_activation' ] );
}
/**
* Append cache control header.
*
* @return void
*/
public function append_cache_control_header_on_activation() {
add_filter( 'after_rocket_htaccess_rules', [ $this, 'append_cache_control_header' ] );
}
}
@@ -0,0 +1,39 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
/**
* Subscriber for compatibility with WordPress.com hosting.
*
* @since 3.6.3
*/
class WordPressCom extends AbstractNoCacheHost {
/**
* Array of events this subscriber listens to.
*
* @since 3.6.3
*
* @return array The array of subscribed events.
*/
public static function get_subscribed_events() {
return [
'do_rocket_generate_caching_files' => 'return_false',
'rocket_cache_mandatory_cookies' => 'return_empty_array',
'rocket_display_varnish_options_tab' => 'return_false',
'rocket_set_wp_cache_constant' => 'return_false',
'rocket_generate_advanced_cache_file' => 'return_false',
'after_rocket_clean_domain' => 'purge_wpcom_cache',
];
}
/**
* Purge WordPress.com cache
*
* @since 3.6.3
*
* @return void
*/
public function purge_wpcom_cache() {
wp_cache_flush();
}
}
@@ -0,0 +1,28 @@
<?php
namespace WP_Rocket\ThirdParty;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Null Subscriber.
*
* Provides a base class to extend for common Subscribers.
*
* @since 3.6.3
*/
class NullSubscriber implements Subscriber_Interface {
/**
* Get an array of subscribed events.
*
* To be overloaded with actual subscribed events in extending Subscribers.
*
* @since 3.6.3
*
* @return array
*/
public static function get_subscribed_events() {
return [];
}
}
@@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins\Ads;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Adthrive implements Subscriber_Interface {
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events(): array {
return [
'wp_rocket_upgrade' => [ 'add_delay_js_exclusion_on_plugin_update', 20, 2 ],
'activate_adthrive-ads/adthrive-ads.php' => 'add_delay_js_exclusion',
'pre_update_option_wp_rocket_settings' => [ 'maybe_add_delay_js_exclusion', 10, 2 ],
];
}
/**
* Adds adthrive to delay JS exclusion field
*
* @since 3.9.3
*
* @return void
*/
public function add_delay_js_exclusion() {
$options = get_option( 'wp_rocket_settings', [] );
if (
! isset( $options['delay_js'] )
||
empty( $options['delay_js'] )
) {
return;
}
$exclusions = $options['delay_js_exclusions'] ?? [];
if ( in_array( 'adthrive', $exclusions, true ) ) {
return;
}
$exclusions[] = 'adthrive';
$options['delay_js_exclusions'] = $exclusions;
update_option( 'wp_rocket_settings', $options );
}
/**
* Adds adthrive to delay JS exclusion field on update to 3.9.3
*
* @since 3.9.3
*
* @param string $new_version Plugin new version.
* @param string $old_version Plugin old version.
*
* @return void
*/
public function add_delay_js_exclusion_on_plugin_update( $new_version, $old_version ) {
if ( version_compare( $old_version, '3.9.3', '>' ) ) {
return;
}
if ( ! is_plugin_active( 'adthrive-ads/adthrive-ads.php' ) ) {
return;
}
$this->add_delay_js_exclusion();
}
/**
* Adds Adthrive pattern when saving WPR options and Adthrive is enabled
*
* @since 3.9.3
*
* @param array $value The new, unserialized option value.
* @param array $old_value The old option value.
*
* @return array
*/
public function maybe_add_delay_js_exclusion( $value, $old_value ): array {
if ( ! is_plugin_active( 'adthrive-ads/adthrive-ads.php' ) ) {
return $value;
}
if ( empty( $value['delay_js'] ) ) {
return $value;
}
if (
isset( $old_value['delay_js'] )
&&
$old_value['delay_js'] === $value['delay_js']
) {
return $value;
}
if (
isset( $value['delay_js_exclusions'] )
&&
in_array( 'adthrive', $value['delay_js_exclusions'], true )
) {
return $value;
}
$value['delay_js_exclusions'][] = 'adthrive';
return $value;
}
}
@@ -0,0 +1,503 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins\CDN;
use WP_Rocket\Admin\{Options, Options_Data};
use WP_Rocket\Engine\Admin\Beacon\Beacon;
use WP_Rocket\Engine\Deactivation\DeactivationInterface;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Compatibility class for cloudflare.
*/
class Cloudflare implements Subscriber_Interface, DeactivationInterface {
/**
* Options instance.
*
* @var Options_Data
*/
private $options;
/**
* Options API instance.
*
* @var Options
*/
private $options_api;
/**
* Beacon
*
* @var Beacon Beacon instance.
*/
private $beacon;
/**
* CloudflareFacade instance.
*
* @var CloudflareFacade
*/
private $facade;
/**
* Constructor.
*
* @param Options_Data $options Options instance.
* @param Options $options_api Options API instance.
* @param Beacon $beacon Beacon instance.
* @param CloudflareFacade $facade CloudflareFacade instance.
*/
public function __construct( Options_Data $options, Options $options_api, Beacon $beacon, CloudflareFacade $facade ) {
$this->options = $options;
$this->options_api = $options_api;
$this->beacon = $beacon;
$this->facade = $facade;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'admin_notices' => [
[ 'display_server_pushing_mode_notice' ],
[ 'display_apo_cookies_notice' ],
[ 'display_apo_cache_notice' ],
],
'rocket_display_input_do_cloudflare' => 'hide_addon_radio',
'rocket_cloudflare_field_settings' => 'update_addon_field',
'pre_get_rocket_option_do_cloudflare' => 'disable_cloudflare_option',
'after_rocket_clean_domain' => 'purge_cloudflare',
'after_rocket_clean_files' => 'purge_cloudflare_partial',
'rocket_rucss_complete_job_status' => 'purge_cloudflare_after_usedcss',
'rocket_rucss_after_clearing_usedcss' => 'purge_cloudflare_after_usedcss',
'admin_post_rocket_enable_separate_mobile_cache' => 'enable_separate_mobile_cache',
'rocket_cdn_helper_addons' => 'add_cdn_helper_message',
'init' => 'unregister_cloudflare_clean_on_post',
];
}
/**
* Display notice for server pushing mode.
*
* @return void
*/
public function display_server_pushing_mode_notice() {
if ( ! rocket_get_constant( 'CLOUDFLARE_PLUGIN_DIR' ) ) {
return;
}
if ( ! rocket_get_constant( 'CLOUDFLARE_HTTP2_SERVER_PUSH_ACTIVE' ) ) {
return;
}
$screen = get_current_screen();
// If current screen is wprocket settings.
if (
isset( $screen->id )
&&
'settings_page_wprocket' !== $screen->id
) {
return;
}
// if current user has required capapabilities.
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
// If RUCSS is enabled.
if ( ! (bool) $this->options->get( 'remove_unused_css', 0 ) ) {
return;
}
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
$notice_name = 'cloudflare_server_push';
if ( in_array( $notice_name, (array) $boxes, true ) ) {
return;
}
$message = sprintf(
// translators: %1$s = plugin name.
__( '%1$s: Cloudflare\'s HTTP/2 Server Push is incompatible with the features of Remove Unused CSS and Combine CSS files. We strongly recommend disabling it.', 'rocket' ),
'<strong>WP Rocket</strong>'
);
rocket_notice_html(
[
'status' => 'warning',
'dismissible' => '',
'message' => $message,
'id' => 'cloudflare_server_push_notice',
'dismiss_button' => $notice_name,
'dismiss_button_class' => 'button-primary',
]
);
}
/**
* Hide WP Rocket CF Addon activation button if the official CF plugin is enabled
*
* @param bool $enable True to display, False otherwise.
*
* @return bool
*/
public function hide_addon_radio( $enable ) {
if ( ! $this->is_plugin_active() ) {
return $enable;
}
return false;
}
/**
* Updates WP Rocket CF Addon field when the official CF plugin is enabled
*
* @param array $settings Array of values to populate the field.
*
* @return array
*/
public function update_addon_field( $settings ) {
if ( ! $this->is_plugin_active() ) {
return $settings;
}
$settings['do_cloudflare']['title'] = __( 'Your site is using the official Cloudflare plugin. We have enabled Cloudflare auto-purge for compatibility. If you have APO activated, it is also compatible.', 'rocket' );
$settings['do_cloudflare']['description'] = __( 'Cloudflare cache will be purged each time WP Rocket clears its cache to ensure content is always up-to-date.', 'rocket' );
$settings['do_cloudflare']['helper'] = '';
$settings['do_cloudflare']['settings_page'] = '';
return $settings;
}
/**
* Disable WP Rocket CF option when Cloudflare plugin is enabled
*
* @param mixed $value Pre option value.
*
* @return bool
*/
public function disable_cloudflare_option( $value ) {
if ( ! $this->is_plugin_active() ) {
return $value;
}
return false;
}
/**
* Display a notice when APO is enabled and mandatory/dynamic cookies exists
*
* @return void
*/
public function display_apo_cookies_notice() {
if ( ! $this->can_display_notice() ) {
return;
}
if (
empty( get_rocket_cache_mandatory_cookies() )
&&
empty( get_rocket_cache_dynamic_cookies() )
) {
return;
}
$doc = $this->beacon->get_suggest( 'cloudflare_apo' );
$message = sprintf(
// Translators: %1$s = strong opening tag, %2$s = strong closing tag.
__( '%1$sWP Rocket:%2$s You are using "Dynamic Cookies Cache". Cloudflare APO is not yet compatible with that feature.', 'rocket' ) . '<br>',
'<strong>',
'</strong>'
);
$message .= sprintf(
// Translators:%1$s = opening <a> tag, %2$s = closing </a> tag.
__( 'You should either disable Cloudflare APO or check with the theme/plugin requiring the use of “Dynamic Cookies Cache” developers for an alternative way to be page-cache friendly. %1$sMore info%2$s', 'rocket' ),
'<a href="' . esc_url( $doc['url'] ) . '" data-beacon-article="' . esc_attr( $doc['id'] ) . '" target="_blank" rel="noopener noreferrer">',
'</a>'
);
rocket_notice_html(
[
'status' => 'warning',
'dismissible' => '',
'message' => $message,
]
);
}
/**
* Display a notice when there is a mismatch between WP Rocket separate cache by mobile value and APO cache by device type
*
* @return void
*/
public function display_apo_cache_notice() {
if ( ! $this->can_display_notice() ) {
return;
}
$cf_device_type = get_option( 'automatic_platform_optimization_cache_by_device_type', [] );
if ( ! key_exists( 'value', $cf_device_type ) ) {
return;
}
$mobile_cache = $this->options->get( 'do_caching_mobile_files', 0 );
if ( (int) $mobile_cache === (int) $cf_device_type['value'] ) {
return;
}
$doc = $this->beacon->get_suggest( 'cloudflare_apo' );
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if (
1 === (int) $mobile_cache
&&
0 === (int) $cf_device_type['value']
) {
rocket_notice_html(
[
'status' => 'warning',
'dismissible' => '',
'message' => sprintf(
// Translators: %1$s = strong opening tag, %2$s = strong closing tag, %3$s = opening <a> tag, %4$s = closing </a> tag, %5$s = opening <a> tag.
__( '%1$sWP Rocket:%2$s You are using "Separate cache files for mobile devices". You need to activate "Cache by Device Type" %3$ssetting%5$s on Cloudflare APO to serve the right version of the cache. %4$sMore info%5$s', 'rocket' ),
'<strong>',
'</strong>',
'<a href="' . esc_url( admin_url( 'options-general.php?page=cloudflare' ) ) . '">',
'<a href="' . esc_url( $doc['url'] ) . '" data-beacon-article="' . esc_attr( $doc['id'] ) . '" target="_blank" rel="noopener noreferrer">',
'</a>'
),
]
);
} elseif (
0 === (int) $mobile_cache
&&
1 === (int) $cf_device_type['value']
&&
! in_array( __FUNCTION__, (array) $boxes, true )
) {
rocket_notice_html(
[
'status' => 'warning',
'message' => sprintf(
// Translators: %1$s = strong opening tag, %2$s = strong closing tag.
__( '%1$sWP Rocket:%2$s You have "Cache by Device Type" enabled on Cloudflare APO. If you judge it necessary for the website to have a different cache on mobile and desktop, we suggest you enable our “Separate Cache Files for Mobiles Devices” to ensure the generated cache is accurate.', 'rocket' ),
'<strong>',
'</strong>'
),
'dismiss_button' => __FUNCTION__,
'dismissible' => '',
'action' => 'enable_separate_mobile_cache',
]
);
}
}
/**
* Checks if APO notices should be displayed
*
* @return bool
*/
private function can_display_notice(): bool {
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return false;
}
$screen = get_current_screen();
if (
isset( $screen->id )
&&
'settings_page_wprocket' !== $screen->id
) {
return false;
}
if ( ! $this->is_plugin_active() ) {
return false;
}
return $this->is_apo_enabled();
}
/**
* Purge everything on Cloudflare
*
* @return void
*/
public function purge_cloudflare() {
if ( ! $this->is_plugin_active() ) {
return;
}
$this->facade->purge_everything();
}
/**
* Purges posts when using purge this URL button
*
* @param array $urls Array of URLs.
*
* @return void
*/
public function purge_cloudflare_partial( $urls ) {
if ( ! $this->is_plugin_active() ) {
return;
}
$post_ids = array_filter( array_map( 'url_to_postid', $urls ) );
$this->facade->purge_urls( $post_ids );
}
/**
* Purges CF after Used CSS generation or clean
*
* @param string $url URL to purge.
*
* @return void
*/
public function purge_cloudflare_after_usedcss( $url ) {
if ( ! $this->is_plugin_active() ) {
return;
}
$post_id = url_to_postid( $url );
if ( empty( $post_id ) ) {
return;
}
$this->facade->purge_urls( $post_id );
}
/**
* Enable separate cache for mobile option
*
* @return void
*/
public function enable_separate_mobile_cache() {
check_admin_referer( 'rocket_enable_separate_mobile_cache' );
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
$this->options->set( 'cache_mobile', 1 );
$this->options->set( 'do_caching_mobile_files', 1 );
$this->options_api->set( 'settings', $this->options->get_options() );
wp_safe_redirect( wp_get_referer() );
rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) ? wp_die() : exit;
}
/**
* Checks if CF plugin is enabled & credentials saved
*
* @return bool
*/
private function is_plugin_active(): bool {
if ( ! is_plugin_active( 'cloudflare/cloudflare.php' ) ) {
return false;
}
if (
empty( get_option( 'cloudflare_api_email', '' ) )
||
empty( get_option( 'cloudflare_api_key', '' ) )
||
empty( get_option( 'cloudflare_cached_domain_name', '' ) )
) {
return false;
}
return true;
}
/**
* Checks if CF APO is enabled
*
* @return bool
*/
private function is_apo_enabled(): bool {
$is_apo_enabled = get_option( 'automatic_platform_optimization', [] );
if ( ! key_exists( 'value', $is_apo_enabled ) ) {
return false;
}
return (bool) $is_apo_enabled['value'];
}
/**
* Add the helper message on the CDN settings.
*
* @param string[] $addons Name from the addon that requires the helper message.
* @return string[]
*/
public function add_cdn_helper_message( array $addons ): array {
if ( ! $this->is_plugin_active() ) {
return $addons;
}
$addons[] = 'Cloudflare';
return $addons;
}
/**
* Purge Cloudflare on deactivate.
*
* @return void
*/
public function deactivate() {
$this->purge_cloudflare();
}
/**
* Unregister Call on clean posts.
*
* @return void
*/
public function unregister_cloudflare_clean_on_post() {
$this->unregister_callback( 'deleted_post', 'purgeCacheByRelevantURLs' );
$this->unregister_callback( 'transition_post_status', 'purgeCacheOnPostStatusChange', PHP_INT_MAX );
}
/**
* Unregister a callback.
*
* @param string $hook Hook on which to unregister.
* @param string $method The callback to unregister.
* @param int $priority the priority from the callback.
* @return void
*/
protected function unregister_callback( string $hook, string $method, int $priority = 10 ) {
global $wp_filter;
if ( ! key_exists( $hook, $wp_filter ) ) {
return;
}
$original_wp_filter = $wp_filter[ $hook ]->callbacks;
if ( ! key_exists( $priority, $original_wp_filter ) ) {
return;
}
foreach ( $original_wp_filter[ $priority ] as $key => $config ) {
if ( substr( $key, - strlen( $method ) ) !== $method ) {
continue;
}
unset( $wp_filter[ $hook ]->callbacks[ $priority ][ $key ] );
}
}
}
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins\CDN;
use CF\WordPress\Hooks;
class CloudflareFacade {
/**
* Hooks class instance
*
* @var Hooks
*/
private $hooks;
/**
* Instanciate the hooks class
*
* @return void
*/
private function set_hooks() {
$this->hooks = new Hooks();
}
/**
* Calls purge everything from CF hooks class
*
* @return void
*/
public function purge_everything() {
if ( is_null( $this->hooks ) ) {
$this->set_hooks();
}
$this->hooks->purgeCacheEverything();
}
/**
* Calls purge relevant URLs from CF hooks class
*
* @param int|array $post_ids Post ID or array of post IDs.
*
* @return void
*/
public function purge_urls( $post_ids ) {
if ( is_null( $this->hooks ) ) {
$this->set_hooks();
}
$this->hooks->purgeCacheByRelevantURLs( $post_ids );
}
}
@@ -0,0 +1,48 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with ConvertPlug.
*/
class ConvertPlug implements Subscriber_Interface {
/**
* Subscriber for compatibility with ConvertPlug.
*
* @return array
*/
public static function get_subscribed_events() {
$events = [];
if ( ! self::isActivated() ) {
return $events;
}
$events['rocket_rucss_inline_atts_exclusions'] = 'excluded_from_rucss';
return $events;
}
/**
* Check if the plugin is activated.
*
* @return bool
*/
protected static function isActivated() {
return defined( 'CP_VERSION' );
}
/**
* Exclude css from RUCSS.
*
* @param array $excluded excluded css.
* @return array
*/
public function excluded_from_rucss( $excluded ) {
$excluded[] = 'cp-form-css';
return $excluded;
}
}
@@ -0,0 +1,165 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\Ecommerce;
use WP_Rocket\Event_Management\Event_Manager;
use WP_Rocket\Event_Management\Event_Manager_Aware_Subscriber_Interface;
use WP_Rocket\Traits\Config_Updater;
/**
* BigCommerce compatibility subscriber
*
* @since 3.3.7
*/
class BigCommerce implements Event_Manager_Aware_Subscriber_Interface {
use Config_Updater;
/**
* The WordPress Event Manager
*
* @var Event_Manager;
*/
protected $event_manager;
/**
* {@inheritdoc}
*
* @param Event_Manager $event_manager The WordPress Event Manager.
*/
public function set_event_manager( Event_Manager $event_manager ) {
$this->event_manager = $event_manager;
}
/**
* {@inheritdoc}
*/
public static function get_subscribed_events() {
$events = [
'activate_bigcommerce/bigcommerce.php' => [ 'activate_bigcommerce', 11 ],
'deactivate_bigcommerce/bigcommerce.php' => [ 'deactivate_bigcommerce', 11 ],
];
if ( function_exists( 'bigcommerce_init' ) ) {
$events['update_option_bigcommerce_login_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['update_option_bigcommerce_account_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['update_option_bigcommerce_address_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['update_option_bigcommerce_orders_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['update_option_bigcommerce_cart_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['update_option_bigcommerce_checkout_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['shutdown'] = 'maybe_update_config';
$events['transition_post_status'] = [ 'maybe_exclude_page', 10, 3 ];
$events['rocket_cache_reject_uri'] = [
[ 'exclude_pages' ],
];
}
return $events;
}
/**
* Add exclusions when activating the BigCommerce plugin
*
* @since 3.3.7
*/
public function activate_bigcommerce() {
$this->event_manager->add_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
/**
* Remove exclusions when deactivating the BigCommerce plugin
*
* @since 3.3.7
*/
public function deactivate_bigcommerce() {
$this->event_manager->remove_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
/**
* Maybe regenerate the htaccess & config file if a BigCommerce page is published
*
* @since 3.3.7
*
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param WP_Post $post Post object.
* @return bool
*/
public function maybe_exclude_page( $new_status, $old_status, $post ) {
if ( 'publish' === $old_status || 'publish' !== $new_status ) {
return false;
}
if ( get_option( 'bigcommerce_login_page_id' ) !== $post->ID && get_option( 'bigcommerce_account_page_id' ) !== $post->ID && get_option( 'bigcommerce_address_page_id' ) !== $post->ID && get_option( 'bigcommerce_orders_page_id' ) !== $post->ID && get_option( 'bigcommerce_cart_page_id' ) !== $post->ID && get_option( 'bigcommerce_checkout_page_id' ) !== $post->ID ) {
return false;
}
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
return true;
}
/**
* Exclude BigCommerce login, cart, checkout, account, address and orders pages from caching
*
* @since 3.3.7
*
* @param array $urls An array of excluded pages.
* @return array
*/
public function exclude_pages( $urls ) {
$checkout_urls = $this->exclude_page( get_option( 'bigcommerce_checkout_page_id' ) );
$cart_urls = $this->exclude_page( get_option( 'bigcommerce_cart_page_id' ) );
$account_urls = $this->exclude_page( get_option( 'bigcommerce_account_page_id' ) );
$login_urls = $this->exclude_page( get_option( 'bigcommerce_login_page_id' ) );
$address_urls = $this->exclude_page( get_option( 'bigcommerce_address_page_id' ) );
$orders_urls = $this->exclude_page( get_option( 'bigcommerce_orders_page_id' ) );
return array_merge( $urls, $checkout_urls, $cart_urls, $account_urls, $login_urls, $address_urls, $orders_urls );
}
/**
* Excludes BigCommerce checkout page from cache
*
* @since 3.3.7
*
* @param int $page_id ID of page to exclude.
* @param string $post_type Post type of the page.
* @param string $pattern Pattern to use for the exclusion.
* @return array
*/
private function exclude_page( $page_id, $post_type = 'page', $pattern = '' ) {
$urls = [];
if ( ! $page_id ) {
return $urls;
}
if ( $page_id <= 0 || (int) get_option( 'page_on_front' ) === $page_id ) {
return $urls;
}
if ( 'publish' !== get_post_status( $page_id ) ) {
return $urls;
}
$urls = get_rocket_i18n_translated_post_urls( $page_id, $post_type, $pattern );
return $urls;
}
}
@@ -0,0 +1,633 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\Ecommerce;
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
use WP_Rocket\Event_Management\Event_Manager;
use WP_Rocket\Event_Management\Event_Manager_Aware_Subscriber_Interface;
use WP_Rocket\Logger\Logger;
use WP_Rocket\Traits\Config_Updater;
/**
* WooCommerce compatibility
*
* @since 3.1
*/
class WooCommerceSubscriber implements Event_Manager_Aware_Subscriber_Interface {
use Config_Updater;
/**
* The WordPress Event Manager
*
* @var Event_Manager;
*/
protected $event_manager;
/**
* Delay JS HTML class.
*
* @var HTML
*/
private $delayjs_html;
/**
* WooCommerceSubscriber constructor.
*
* @param HTML $delayjs_html DelayJS HTML class.
*/
public function __construct( HTML $delayjs_html ) {
$this->delayjs_html = $delayjs_html;
}
/**
* {@inheritdoc}
*
* @param Event_Manager $event_manager The WordPress Event Manager.
*/
public function set_event_manager( Event_Manager $event_manager ) {
$this->event_manager = $event_manager;
}
/**
* {@inheritdoc}
*/
public static function get_subscribed_events() {
$events = [
'activate_woocommerce/woocommerce.php' => [ 'activate_woocommerce', 11 ],
'deactivate_woocommerce/woocommerce.php' => [ 'deactivate_woocommerce', 11 ],
];
if ( class_exists( 'WooCommerce' ) ) {
$events['update_option_woocommerce_cart_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['update_option_woocommerce_checkout_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['update_option_woocommerce_myaccount_page_id'] = [ 'after_update_single_option', 10, 2 ];
$events['update_option_woocommerce_default_customer_address'] = [ 'after_update_single_option', 10, 2 ];
$events['shutdown'] = 'maybe_update_config';
$events['woocommerce_save_product_variation'] = 'clean_cache_after_woocommerce_save_product_variation';
$events['transition_post_status'] = [ 'maybe_exclude_page', 10, 3 ];
$events['rocket_cache_reject_uri'] = [
[ 'exclude_pages' ],
];
$events['rocket_preload_exclude_urls'] = [
[ 'exclude_pages' ],
];
$events['rocket_cache_query_strings'] = 'cache_geolocation_query_string';
$events['rocket_cpcss_excluded_taxonomies'] = 'exclude_product_attributes_cpcss';
$events['after_rocket_clean_post_urls'] = [ 'reformat_shop_url_for_preload', 10, 2 ];
$events['rocket_exclude_post_taxonomy'] = 'exclude_product_shipping_taxonomy';
/**
* Filters activation of WooCommerce empty cart caching
*
* @since 3.1
*
* @param bool true to activate, false to deactivate.
*/
if ( apply_filters( 'rocket_cache_wc_empty_cart', true ) ) {
$events['init'] = [ 'serve_cache_empty_cart', 11 ];
$events['template_redirect'] = [ 'cache_empty_cart', -1 ];
$events['switch_theme'] = 'delete_cache_empty_cart';
}
$events['wp_head'] = 'show_empty_product_gallery_with_delayJS';
$events['rocket_delay_js_exclusions'] = 'show_notempty_product_gallery_with_delayJS';
$events['wp_ajax_woocommerce_product_ordering'] = [ 'disallow_rocket_clean_post', 9 ];
$events['woocommerce_after_product_ordering'] = [ 'allow_rocket_clean_post' ];
}
if ( class_exists( 'WC_API' ) ) {
$events['rocket_cache_reject_uri'][] = [ 'exclude_wc_rest_api' ];
}
return $events;
}
/**
* Reformat Shop URL to prevent error on preload.
*
* @param array $urls urls cleared.
* @param WP_Post $object post object.
* @return array
*/
public function reformat_shop_url_for_preload( array $urls, $object ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
$post_type = $object->post_type;
if ( 'product' !== $post_type ) {
return $urls;
}
$post_type_archive = get_post_type_archive_link( $post_type );
if ( ! $post_type_archive ) {
return $urls;
}
// Rename the caching filename for SSL URLs.
$filename = 'index';
if ( is_ssl() ) {
$filename .= '-https';
}
$post_type_archive = trailingslashit( $post_type_archive );
$index_url = $post_type_archive . $filename . '.html';
$index_url_gzip = $post_type_archive . $filename . '.html_gzip';
$pagination_url = $post_type_archive . $GLOBALS['wp_rewrite']->pagination_base;
foreach ( $urls as $index => $url ) {
if ( in_array( $url, [ $index_url, $index_url_gzip, $pagination_url ], true ) ) {
$urls[ $index ] = $post_type_archive;
}
}
return array_unique( $urls );
}
/**
* Add query string to exclusion when activating the plugin
*
* @since 2.8.6
* @author Rémy Perona
*/
public function activate_woocommerce() {
$this->event_manager->add_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
$this->event_manager->add_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_wc_rest_api' ] );
$this->event_manager->add_callback( 'rocket_cache_query_strings', [ $this, 'cache_geolocation_query_string' ] );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
/**
* Remove query string from exclusion when deactivating the plugin
*
* @since 2.8.6
* @author Rémy Perona
*/
public function deactivate_woocommerce() {
$this->event_manager->remove_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
$this->event_manager->remove_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_wc_rest_api' ] );
$this->event_manager->remove_callback( 'rocket_cache_query_strings', [ $this, 'cache_geolocation_query_string' ] );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
/**
* Clean product cache on variation update
*
* @since 2.9
* @author Remy Perona
*
* @param int $variation_id ID of the variation.
* @return bool
*/
public function clean_cache_after_woocommerce_save_product_variation( $variation_id ) {
$product_id = wp_get_post_parent_id( $variation_id );
if ( ! $product_id ) {
return false;
}
rocket_clean_post( $product_id );
return true;
}
/**
* Maybe regenerate the htaccess & config file if a WooCommerce page is published
*
* @since 3.1
* @author Remy Perona
*
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param WP_Post $post Post object.
* @return bool
*/
public function maybe_exclude_page( $new_status, $old_status, $post ) {
if ( 'publish' === $old_status || 'publish' !== $new_status ) {
return false;
}
if ( ! function_exists( 'wc_get_page_id' ) ) {
return false;
}
if ( wc_get_page_id( 'checkout' ) !== $post->ID && wc_get_page_id( 'cart' ) !== $post->ID && wc_get_page_id( 'myaccount' ) !== $post->ID ) {
return false;
}
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
return true;
}
/**
* Exclude WooCommerce cart, checkout and account pages from caching
*
* @since 2.11 Moved to 3rd party
* @since 2.4
*
* @param array $urls An array of excluded pages.
* @return array Updated array of excluded pages
*/
public function exclude_pages( $urls ) {
if ( ! function_exists( 'wc_get_page_id' ) ) {
return $urls;
}
$checkout_urls = $this->exclude_page( wc_get_page_id( 'checkout' ), 'page', '?(.*)' );
$cart_urls = $this->exclude_page( wc_get_page_id( 'cart' ) );
$account_urls = $this->exclude_page( wc_get_page_id( 'myaccount' ), 'page', '?(.*)' );
return array_merge( $urls, $checkout_urls, $cart_urls, $account_urls );
}
/**
* Excludes WooCommerce checkout page from cache
*
* @since 3.1
* @author Remy Perona
*
* @param int $page_id ID of page to exclude.
* @param string $post_type Post type of the page.
* @param string $pattern Pattern to use for the exclusion.
* @return array
*/
private function exclude_page( $page_id, $post_type = 'page', $pattern = '' ) {
global $wp_rewrite;
$urls = [];
if ( $page_id <= 0 || (int) get_option( 'page_on_front' ) === $page_id ) {
return $urls;
}
if ( 'publish' !== get_post_status( $page_id ) ) {
return $urls;
}
if ( $wp_rewrite->use_trailing_slashes ) {
$pattern = "?$pattern";
}
$urls = get_rocket_i18n_translated_post_urls( $page_id, $post_type, $pattern );
return $urls;
}
/**
* Automatically cache v query string when WC geolocation with cache compatibility option is active
*
* @since 2.8.6
* @author Rémy Perona
*
* @param array $query_strings list of query strings to cache.
* @return array Updated list of query strings to cache
*/
public function cache_geolocation_query_string( $query_strings ) {
if ( 'geolocation_ajax' !== get_option( 'woocommerce_default_customer_address' ) ) {
return $query_strings;
}
$query_strings[] = 'v';
return $query_strings;
}
/**
* Returns WooCommerce API endpoint
*
* @since 3.1
* @author Remy Perona
*
* @return string
*/
private function get_wc_api_endpoint() {
return home_url( '/wc-api/v(.*)' );
}
/**
* Exclude WooCommerce REST API URL from cache
*
* @since 2.6.5
*
* @param array $urls URLs to exclude from cache.
* @return array Updated list of URLs to exclude from cache
*/
public function exclude_wc_rest_api( $urls ) {
/**
* By default, don't cache the WooCommerce REST API.
*
* @since 2.6.5
*
* @param bool false will force to cache the WooCommerce REST API
*/
if ( apply_filters( 'rocket_cache_reject_wc_rest_api', true ) ) {
$urls[] = rocket_clean_exclude_file( $this->get_wc_api_endpoint() );
}
return $urls;
}
/**
* Serves the empty cart cache
*
* @since 3.1
* @author Remy Perona
*
* @return void
*/
public function serve_cache_empty_cart() {
if ( ! $this->is_get_refreshed_fragments() || rocket_bypass() ) {
return;
}
$cart = $this->get_cache_empty_cart();
if ( false !== $cart ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
echo $cart; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
die();
}
}
/**
* Creates the empty cart cache
*
* @since 3.1
* @author Remy Perona
*
* @return void
*/
public function cache_empty_cart() {
if ( ! $this->is_get_refreshed_fragments() || rocket_bypass() ) {
return;
}
$cart = $this->get_cache_empty_cart();
if ( false !== $cart ) {
return;
}
ob_start( [ $this, 'save_cache_empty_cart' ] );
}
/**
* Gets the empty cart cache
*
* @since 3.1
* @author Remy Perona
*
* @return string
*/
private function get_cache_empty_cart() {
$lang = rocket_get_current_language();
if ( $lang ) {
return get_transient( 'rocket_get_refreshed_fragments_cache_' . $lang );
}
return get_transient( 'rocket_get_refreshed_fragments_cache' );
}
/**
* Saves the empty cart JSON in a transient
*
* @since 3.1
* @author Remy Perona
*
* @param string $content Current buffer content.
* @return string
*/
private function save_cache_empty_cart( $content ) {
$lang = rocket_get_current_language();
if ( $lang ) {
set_transient( 'rocket_get_refreshed_fragments_cache_' . $lang, $content, 7 * DAY_IN_SECONDS );
return $content;
}
set_transient( 'rocket_get_refreshed_fragments_cache', $content, 7 * DAY_IN_SECONDS );
return $content;
}
/**
* Checks if the request is for get_refreshed_fragments and the cart is empty
*
* @since 3.1
* @author Remy Perona
*
* @return boolean
*/
private function is_get_refreshed_fragments() {
if ( ! isset( $_GET['wc-ajax'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return false;
}
if ( 'get_refreshed_fragments' !== $_GET['wc-ajax'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return false;
}
if ( ! empty( $_COOKIE['woocommerce_cart_hash'] ) ) {
return false;
}
if ( ! empty( $_COOKIE['woocommerce_items_in_cart'] ) ) {
return false;
}
return true;
}
/**
* Deletes the empty cart cache
*
* @since 3.1
* @author Remy Perona
*
* @return void
*/
public function delete_cache_empty_cart() {
$langs = get_rocket_i18n_code();
if ( $langs ) {
foreach ( $langs as $lang ) {
delete_transient( 'rocket_get_refreshed_fragments_cache_' . $lang );
}
}
delete_transient( 'rocket_get_refreshed_fragments_cache' );
}
/**
* Excludes WC product attributes taxonomies from CPCSS generation
*
* @since 3.3.5
* @author Remy Perona
*
* @param array $excluded_taxonomies Taxonomies excluded from CPCSS generation.
* @return array
*/
public function exclude_product_attributes_cpcss( $excluded_taxonomies ) {
if ( ! function_exists( 'wc_get_attribute_taxonomy_names' ) ) {
return $excluded_taxonomies;
}
return array_merge( $excluded_taxonomies, wc_get_attribute_taxonomy_names() );
}
/**
* Exclude product_shipping_class taxonomy from post purge
*
* @since 3.9.1
*
* @param array $excluded_taxonomies Array of excluded taxonomies names.
*
* @return array
*/
public function exclude_product_shipping_taxonomy( $excluded_taxonomies ) {
$excluded_taxonomies[] = 'product_shipping_class';
return $excluded_taxonomies;
}
/**
* Check if current product page has images in gallery.
*
* @since 3.9.1
*
* @return bool
*/
private function product_has_gallery_images() {
$product = wc_get_product( get_the_ID() );
if ( empty( $product ) ) {
return false;
}
return ! empty( $product->get_gallery_image_ids() );
}
/**
* Show product gallery main image directly when delay JS is enabled.
*
* @since 3.9.1
*/
public function show_empty_product_gallery_with_delayJS() {
if ( ! $this->delayjs_html->is_allowed() ) {
return;
}
if ( ! is_product() ) {
return;
}
if ( $this->product_has_gallery_images() ) {
return;
}
echo '<style>.woocommerce-product-gallery{ opacity: 1 !important; }</style>';
}
/**
* Exclude some JS files from delay JS when product gallery has images.
*
* @since 3.9.1
*
* @param array $exclusions Exclusions array.
*
* @return array
*/
public function show_notempty_product_gallery_with_delayJS( $exclusions = [] ): array {
global $wp_version;
if ( ! is_array( $exclusions ) ) {
$exclusions = (array) $exclusions;
}
if ( ! $this->delayjs_html->is_allowed() ) {
return $exclusions;
}
if ( ! is_product() ) {
return $exclusions;
}
if ( ! $this->product_has_gallery_images() ) {
return $exclusions;
}
$exclusions_gallery = [
'/jquery-?[0-9.]*(.min|.slim|.slim.min)?.js',
'/woocommerce/assets/js/zoom/jquery.zoom(.min)?.js',
'/woocommerce/assets/js/photoswipe/',
'/woocommerce/assets/js/flexslider/jquery.flexslider(.min)?.js',
'/woocommerce/assets/js/frontend/single-product(.min)?.js',
];
if (
isset( $wp_version )
&&
version_compare( $wp_version, '5.7', '<' )
) {
$exclusions_gallery[] = '/jquery-migrate(.min)?.js';
}
/**
* Filters the JS files excluded from delay JS when WC product gallery has images.
*
* @since 3.10.2
*
* @param array $exclusions_gallery Array of excluded filepaths.
*/
$exclusions_gallery = apply_filters( 'rocket_wc_product_gallery_delay_js_exclusions', $exclusions_gallery );
return array_merge( $exclusions, $exclusions_gallery );
}
/**
* Disable post cache clearing during product sorting.
*
* @return void
*/
public function disallow_rocket_clean_post(): void {
$this->event_manager->remove_callback( 'clean_post_cache', 'rocket_clean_post' );
}
/**
* Re-enable post cache clearing after product sorting.
*
* @param integer $product_id ID of sorted product.
* @return void
*/
public function allow_rocket_clean_post( int $product_id ): void {
$urls = [];
$category_list = wc_get_product_category_list( $product_id );
if ( preg_match_all( '/<a\s+(?:[^>]*?\s+)?href=(["\'])(?<urls>.*?)\1/i', $category_list, $matches ) ) {
$urls = $matches['urls'];
}
$shop_page = get_permalink( wc_get_page_id( 'shop' ) );
if ( empty( $shop_page ) ) {
$shop_page = home_url( 'shop' );
}
$urls[] = $shop_page;
rocket_clean_files( $urls );
$this->event_manager->add_callback( 'clean_post_cache', 'rocket_clean_post' );
}
}
@@ -0,0 +1,310 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins\I18n;
use TRP_Translate_Press;
use WP_Rocket\Event_Management\Subscriber_Interface;
class TranslatePress implements Subscriber_Interface {
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! class_exists( 'TRP_Translate_Press' ) ) {
return [];
}
return [
'rocket_rucss_is_home_url' => [ 'detect_homepage', 10, 2 ],
'rocket_has_i18n' => 'is_translatepress',
'rocket_i18n_admin_bar_menu' => 'add_langs_to_admin_bar',
'rocket_i18n_current_language' => 'set_current_language',
'rocket_get_i18n_uri' => 'get_active_languages_uri',
'rocket_get_i18n_code' => 'get_active_languages_codes',
'rocket_i18n_subdomains' => 'get_active_languages_uri',
'rocket_i18n_home_url' => [ 'get_home_url_for_lang', 10, 2 ],
'rocket_i18n_translated_post_urls' => [ 'get_translated_post_urls', 10, 4 ],
'post_updated' => 'clear_post_languages',
'trp_save_editor_translations_regular_strings' => [ 'clear_post_after_updating_translation', 10, 2 ],
];
}
/**
* Detect homepage.
*
* @param string $home_url home url.
* @param string $url url of current page.
* @return string
*/
public function detect_homepage( $home_url, $url ) {
$translatepress = TRP_Translate_Press::get_trp_instance();
$converter = $translatepress->get_component( 'url_converter' );
$language = $converter->get_lang_from_url_string( $url );
$url_language = $converter->get_url_for_language( $language, home_url() );
return untrailingslashit( $url ) === untrailingslashit( $url_language ) ? $url : $home_url;
}
/**
* Adds TranslatePress as identifier for i18n detection
*
* @param string|bool $identifier An identifier value, false otherwise.
*
* @return string|bool
*/
public function is_translatepress( $identifier ) {
if (
function_exists( 'trp_get_languages' )
&&
! empty( trp_get_languages( 'nodefault' ) )
) {
return 'translatepress';
}
return $identifier;
}
/**
* Adds languages to the admin bar menu
*
* @param array $langlinks Array of languages.
*
* @return array
*/
public function add_langs_to_admin_bar( $langlinks ) {
$translatepress = TRP_Translate_Press::get_trp_instance();
$language_switcher = $translatepress->get_component( 'language_switcher' );
$settings = $translatepress->get_component( 'settings' );
$languages = $translatepress->get_component( 'languages' );
$trp_settings = $settings->get_settings();
$languages_to_display = $trp_settings['publish-languages'];
$published_languages = $languages->get_language_names( $languages_to_display );
foreach ( $published_languages as $code => $name ) {
$langlinks[ $code ] = [
'code' => $trp_settings['url-slugs'][ $code ],
'flag' => $language_switcher->add_flag( $code, $name ),
'anchor' => $name,
];
}
return $langlinks;
}
/**
* Sets the current language value
*
* @param string|bool $current_language Current language.
*
* @return string|bool
*/
public function set_current_language( $current_language ) {
if ( empty( $GLOBALS['TRP_LANGUAGE'] ) ) {
return $current_language;
}
return $GLOBALS['TRP_LANGUAGE'];
}
/**
* Gets URLs for active languages
*
* @param array $urls Array of active languages URI.
*
* @return array
*/
public function get_active_languages_uri( $urls ) {
if ( ! is_array( $urls ) ) {
$urls = (array) $urls;
}
$home_url = home_url();
$translatepress = TRP_Translate_Press::get_trp_instance();
$settings = $translatepress->get_component( 'settings' );
$languages = $translatepress->get_component( 'languages' );
$converter = $translatepress->get_component( 'url_converter' );
$trp_settings = $settings->get_settings();
$languages_to_display = $trp_settings['publish-languages'];
$published_languages = $languages->get_language_names( $languages_to_display );
foreach ( $published_languages as $code => $name ) {
$urls[] = $converter->get_url_for_language( $code, $home_url );
}
return $urls;
}
/**
* Gets the active languages slugs
*
* @param Array $codes Array of languages codes.
*
* @return array
*/
public function get_active_languages_codes( $codes ) {
if ( ! is_array( $codes ) ) {
$codes = (array) $codes;
}
$translatepress = TRP_Translate_Press::get_trp_instance();
$settings = $translatepress->get_component( 'settings' );
$languages = $translatepress->get_component( 'languages' );
$trp_settings = $settings->get_settings();
$languages_to_display = $trp_settings['publish-languages'];
$published_languages = $languages->get_language_names( $languages_to_display );
foreach ( $published_languages as $code => $name ) {
$codes[] = $trp_settings['url-slugs'][ $code ];
}
return $codes;
}
/**
* Gets home URL in given language
*
* @param string $home_url Home URL.
* @param string $lang Language code.
*
* @return string
*/
public function get_home_url_for_lang( $home_url, $lang ) {
if ( empty( $lang ) ) {
return $home_url;
}
$translatepress = TRP_Translate_Press::get_trp_instance();
$converter = $translatepress->get_component( 'url_converter' );
$settings = $translatepress->get_component( 'settings' );
$trp_settings = $settings->get_settings();
$code = '';
add_filter( 'trp_add_language_to_home_url_check_for_admin', '__return_false' );
foreach ( $trp_settings['url-slugs'] as $index => $slug ) {
if ( $lang === $slug ) {
$code = $index;
break;
}
}
$url = $converter->get_url_for_language( $code, $home_url );
remove_filter( 'trp_add_language_to_home_url_check_for_admin', '__return_false' );
return $url;
}
/**
* Gets all translations URLs for a post
*
* @param array $urls Array of translated URLs.
* @param string $url URL to use.
* @param string $post_type Post type.
* @param string $regex Pattern to include at the end.
*
* @return array
*/
public function get_translated_post_urls( $urls, $url, $post_type, $regex ) {
if ( ! is_array( $urls ) ) {
$urls = (array) $urls;
}
$translatepress = TRP_Translate_Press::get_trp_instance();
$settings = $translatepress->get_component( 'settings' );
$languages = $translatepress->get_component( 'languages' );
$converter = $translatepress->get_component( 'url_converter' );
$trp_settings = $settings->get_settings();
$languages_to_display = $trp_settings['publish-languages'];
$published_languages = $languages->get_language_names( $languages_to_display );
foreach ( $published_languages as $code => $name ) {
$urls[] = wp_parse_url( $converter->get_url_for_language( $code, $url ), PHP_URL_PATH ) . $regex;
}
return $urls;
}
/**
* Clear all languages of a specific post
*
* @param int $post_id Post ID.
*
* @return void
*/
public function clear_post_languages( $post_id ) {
$translatepress = TRP_Translate_Press::get_trp_instance();
$converter = $translatepress->get_component( 'url_converter' );
$settings = $translatepress->get_component( 'settings' );
$trp_settings = $settings->get_settings();
add_filter( 'trp_add_language_to_home_url_check_for_admin', '__return_false' );
$clear_urls = [];
$default_permalink = get_permalink( $post_id );
foreach ( $trp_settings['translation-languages'] as $language ) {
if ( $language === $trp_settings['default-language'] ) {
continue;
}
$clear_urls[] = $converter->get_url_for_language( $language, $default_permalink, '' );
}
remove_filter( 'trp_add_language_to_home_url_check_for_admin', '__return_false' );
if ( empty( $clear_urls ) ) {
return;
}
rocket_clean_files( $clear_urls );
}
/**
* Clear the post cache when the translation is updated
*
* @param array $update_strings Array of updated strings.
* @param array $settings Array of settings.
*
* @return void
*/
public function clear_post_after_updating_translation( $update_strings, $settings ) {
$translatepress = TRP_Translate_Press::get_trp_instance();
$converter = $translatepress->get_component( 'url_converter' );
if ( empty( $_POST['url'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
return;
}
$url = esc_url_raw( wp_unslash( $_POST['url'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
$clear_urls = [];
$current_url = remove_query_arg( 'trp-edit-translation', $url );
foreach ( $settings['translation-languages'] as $language ) {
if ( ! empty( $update_strings[ $language ] ) ) {
$clear_urls[] = $converter->get_url_for_language( $language, $current_url, '' );
}
}
rocket_clean_files( $clear_urls );
}
}
@@ -0,0 +1,195 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\I18n;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Filesystem_Direct;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
/**
* Subscriber for compatibility with WPML.
*/
class WPML implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Filesystem instance.
*
* @var WP_Filesystem_Direct
*/
protected $filesystem;
/**
* Instantiate class.
*
* @param WP_Filesystem_Direct $filesystem Filesystem instance.
*/
public function __construct( WP_Filesystem_Direct $filesystem = null ) {
$this->filesystem = ! empty( $filesystem ) ? $filesystem : rocket_direct_filesystem();
}
/**
* Events for subscriber to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
$events = [
'activate_sitepress-multilingual-cms/sitepress.php' => 'maybe_clear_on_disable',
'deactivate_sitepress-multilingual-cms/sitepress.php' => 'maybe_clear_on_disable',
];
if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) {
return $events;
}
$events['rocket_rucss_is_home_url'] = [ 'is_secondary_home', 10, 2 ];
$events['rocket_preload_all_to_pending_condition'] = 'clean_only_right_domain';
$events['rocket_preload_sitemap_before_queue'] = 'add_languages_sitemaps';
$events['after_rocket_clean_home'] = 'remove_root_cached_files';
$events['after_rocket_clean_domain'] = 'remove_root_cached_files';
$events['pre_update_option_icl_sitepress_settings'] = [ 'on_change_directory_for_default_language_clean_cache', 10, 2 ];
return $events;
}
/**
* Checks if page to be processed is secondary homepage.
*
* @param string $home_url home url.
* @param string $url url of current page.
* @return string
*/
public function is_secondary_home( string $home_url, string $url ): string {
global $sitepress;
// Get active languages on site.
$languages = $sitepress->get_active_languages();
foreach ( $languages as $lang ) {
$lang_url = $sitepress->language_url( $lang['code'] );
// Check if current url is a secondary homepage.
if ( untrailingslashit( $lang_url ) !== $url ) {
continue;
}
return $url;
}
return $home_url;
}
/**
* Add a condition to clean only urls from the domain when it is the case.
*
* @param string $condition condition used to clean URLS in the database.
* @return string
*/
public function clean_only_right_domain( $condition ) {
global $sitepress;
$lang = isset( $_GET['lang'] ) && 'all' !== $_GET['lang'] ? sanitize_key( $_GET['lang'] ) : '';// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! $lang ) {
return $condition;
}
$lang_url = $sitepress->language_url( $lang );
return ' WHERE url LIKE "' . $lang_url . '%"';
}
/**
* Add sitemaps from translations.
*
* @param array $sitemaps list of sitemaps to be fetched.
* @return array
*/
public function add_languages_sitemaps( $sitemaps ) {
global $sitepress;
$new_sitemaps = [];
// Get active languages on site.
$languages = $sitepress->get_active_languages();
$base_url = home_url();
foreach ( $sitemaps as $sitemap ) {
$new_sitemaps[] = $sitemap;
foreach ( $languages as $lang ) {
$lang_url = $sitepress->language_url( $lang['code'] );
$new_sitemaps[] = str_replace( $base_url, $lang_url, $sitemap );
}
}
return array_unique( $new_sitemaps );
}
/**
* Remove root files when WPML is active.
*
* @return void
*/
public function remove_root_cached_files() {
$site_url = home_url();
$host_name = wp_parse_url( $site_url, PHP_URL_HOST );
$cache_folder_path = _rocket_get_wp_rocket_cache_path() . $host_name . '/';
$cache_folder_directory = $this->filesystem->dirlist( $cache_folder_path );
if ( ! is_array( $cache_folder_directory ) || ! is_array( array_keys( $cache_folder_directory ) ) ) {
return;
}
foreach ( array_keys( $cache_folder_directory ) as $entry ) {
if ( $this->filesystem->is_dir( $cache_folder_path . $entry ) ) {
continue;
}
$this->filesystem->delete( $cache_folder_path . $entry );
}
}
/**
* Reset cache when changing the option.
*
* @param array $new new configurations.
* @param array $old old configurations.
*
* @return array
*/
public function on_change_directory_for_default_language_clean_cache( $new, $old ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound
if ( ! is_array( $old ) || ! is_array( $new ) ) {
return $new;
}
if ( ! key_exists( 'urls', $old ) || ! key_exists( 'directory_for_default_language', $old['urls'] ) || ! key_exists( 'urls', $new ) || ! key_exists( 'directory_for_default_language', $new['urls'] ) || $new['urls']['directory_for_default_language'] === $old['urls']['directory_for_default_language'] ) {
return $new;
}
/**
* Reset WP Rocket Preload.
*/
do_action( 'rocket_reset_preload' );
rocket_clean_domain();
return $new;
}
/**
* Clear the cache when the option language directory is enabled.
*
* @return void
*/
public function maybe_clear_on_disable() {
$option = get_option( 'icl_sitepress_settings' );
if ( ! $option || ! is_array( $option ) || ! key_exists( 'urls', $option ) || ! key_exists( 'directory_for_default_language', $option['urls'] ) || false === $option['urls']['directory_for_default_language'] ) {
return;
}
/**
* Reset WP Rocket Preload.
*/
do_action( 'rocket_reset_preload' );
rocket_clean_cache_dir();
rocket_clean_domain();
}
}
@@ -0,0 +1,38 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with Inline Related Posts.
*/
class InlineRelatedPosts implements Subscriber_Interface {
/**
* Subscriber for Inline Related Posts.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! defined( 'IRP_PLUGIN_SLUG' ) ) {
return [];
}
return [ 'rocket_rucss_inline_content_exclusions' => 'exclude_inline_from_rucss' ];
}
/**
* Exclude inline style from RUCSS.
*
* @param array $excluded excluded css.
* @return array
*/
public function exclude_inline_from_rucss( $excluded ) {
$excluded[] = '.centered-text-area';
$excluded[] = '.ctaText';
return $excluded;
}
}
@@ -0,0 +1,61 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class Jetpack implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Option instance.
*
* @var Options_Data
*/
protected $option;
/**
* Instantiate class.
*
* @param Options_Data $option Option instance.
*/
public function __construct( Options_Data $option ) {
$this->option = $option;
}
/**
* Subscribed events.
*/
public static function get_subscribed_events() {
$events = [];
if ( ! class_exists( 'Jetpack' ) ) {
return $events;
}
if ( \Jetpack::is_module_active( 'sitemaps' ) ) {
$events['rocket_sitemap_preload_list'] = 'add_jetpack_sitemap';
}
return $events;
}
/**
* Add Jetpack sitemap to preload list
*
* @param Array $sitemaps Array of sitemaps to preload.
* @return Array Updated Array of sitemaps to preload
*/
public function add_jetpack_sitemap( $sitemaps ) {
if ( ! function_exists( 'jetpack_sitemap_uri' ) ) {
return $sitemaps;
}
$sitemaps['jetpack'] = jetpack_sitemap_uri();
return $sitemaps;
}
}
@@ -0,0 +1,113 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with Mod_pagespeed
*
* @since 3.8.2
*/
class ModPagespeed implements Subscriber_Interface {
/**
* Subscribed events for Pagespeed module.
*
* @since 3.8.2
* @inheritDoc
*/
public static function get_subscribed_events(): array {
return [
'admin_notices' => 'show_admin_notice',
];
}
/**
* Check if mod_pagespeed is enabled on this server with and cache the result on transient.
*
* @since 3.8.2
*
* @return bool Status of mod_pagespeed.
*/
private function has_pagespeed_with_cache() {
$has_pagespeed = get_transient( 'rocket_mod_pagespeed_enabled' );
if ( false === $has_pagespeed ) {
$has_pagespeed = $this->has_pagespeed();
set_transient( 'rocket_mod_pagespeed_enabled', (int) $has_pagespeed, DAY_IN_SECONDS );
}
return 1 === (int) $has_pagespeed;
}
/**
* Check if mod_pagespeed is enabled on this server.
*
* @since 3.8.2
*
* @return bool
*/
private function has_pagespeed(): bool {
if ( false === strpos( ini_get( 'disable_functions' ), 'apache_get_modules' ) ) {
$apache_module_loaded = apache_mod_loaded( 'mod_pagespeed', false );
if ( $apache_module_loaded ) {
return true;
}
}
$home_request = wp_remote_get(
home_url(),
[
'timeout' => 3,
'sslverify' => apply_filters( 'https_local_ssl_verify', false ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
]
);
$headers = wp_remote_retrieve_headers( $home_request );
if ( empty( $headers ) ) {
return false;
}
return ( ! empty( $headers['X-Mod-Pagespeed'] ) || ! empty( $headers['X-Page-Speed'] ) );
}
/**
* Show admin notice message.
*
* @since 3.8.2
*/
public function show_admin_notice() {
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
if ( 'settings_page_wprocket' !== get_current_screen()->id ) {
return;
}
if ( ! $this->has_pagespeed_with_cache() ) {
return;
}
$notice_name = 'rocket_error_mod_pagespeed';
if ( in_array( $notice_name, (array) get_user_meta( get_current_user_id(), 'rocket_boxes', true ), true ) ) {
return;
}
// translators: %1$s is WP Rocket plugin name, %2$s is opening <a> tag, %3$s is closing </a> tag.
$error_message = sprintf( __( '<strong>%1$s</strong>: Mod PageSpeed is not compatible with this plugin and may cause unexpected results. %2$sMore Info%3$s', 'rocket' ), rocket_get_constant( 'WP_ROCKET_PLUGIN_NAME' ), '<a target="_blank" href="https://docs.wp-rocket.me/article/1376-mod-pagespeed">', '</a>' );
rocket_notice_html(
[
'status' => 'error',
'message' => $error_message,
'dismissible' => '',
'dismiss_button' => $notice_name,
]
);
}
}
@@ -0,0 +1,184 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\CDN\Subscriber;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with AMP
*
* @since 3.5.2
*/
class AMP implements Subscriber_Interface {
const QUERY = 'amp';
const AMP_OPTIONS = 'amp-options';
/**
* WP Rocket CDN Subscriber.
*
* @var Subscriber_Interface
*/
private $cdn_subscriber;
/**
* WP Rocket Options instance
*
* @var Options_Data
*/
private $options;
/**
* Constructor
*
* @param Options_Data $options WP Rocket Options instance.
* @param Subscriber_Interface $cdn_subscriber WP Rocket CDN Subscriber.
*/
public function __construct( Options_Data $options, Subscriber_Interface $cdn_subscriber ) {
$this->options = $options;
$this->cdn_subscriber = $cdn_subscriber;
}
/**
* Subscribed events for AMP.
*
* @since 3.5.2
*/
public static function get_subscribed_events() {
$events = [
'activate_amp/amp.php' => 'generate_config_file',
'deactivate_amp/amp.php' => 'generate_config_file',
'wp' => [ 'disable_options_on_amp', 20 ],
'rocket_cache_query_strings' => 'is_amp_compatible_callback',
];
if ( function_exists( 'is_amp_endpoint' ) ) {
$events['update_option_amp-options'] = 'generate_config_file';
$events['rocket_delay_js_exclusions'] = 'exclude_script_from_delay_js';
}
return $events;
}
/**
* Regenerate config file on plugin activation / deactivation.
*
* @since 3.5.2
*/
public function generate_config_file() {
rocket_generate_config_file();
}
/**
* Add compatibility with AMP query string by adding it as a cached query string.
*
* @since 3.5.2
*
* @param array $value WP Rocket cache_query_strings value.
* @return array
*/
public function is_amp_compatible_callback( $value ) {
if ( ! function_exists( 'is_amp_endpoint' ) ) {
return $value;
}
$options = get_option( self::AMP_OPTIONS, [] );
$query_strings = array_diff( $value, [ static::QUERY ] );
if ( empty( $options['theme_support'] ) ) {
return $query_strings;
}
if ( in_array( $options['theme_support'], [ 'transitional', 'reader' ], true ) ) {
$query_strings[] = static::QUERY;
}
return $query_strings;
}
/**
* Removes Minification, DNS Prefetch, LazyLoad, Defer JS when on an AMP document.
*
* This covers AMP documents as output by the official AMP plugin for WordPress
* (https://amp-wp.org/) as well as Web Stories for WordPress (https://wp.stories.google/),
* which both support the `is_amp_endpoint` function checks.
*
* However, in the case of Web Stories, `is_amp_endpoint` is only defined on
* the `wp` action, not earlier. Hence doing the `function_exists` check at this stage
* instead of in the `get_subscribed_events()` method.
*
* @since 3.5.2
*/
public function disable_options_on_amp() {
// No endpoint function means we're not running amp here.
if ( ! function_exists( 'is_amp_endpoint' ) ) {
return;
}
// We can get a false negative from is_amp_endpoint when web stories is active, so we have to make sure neither is in play.
if (
! is_amp_endpoint()
&&
! ( is_singular( 'web-story' ) && ! is_embed() && ! post_password_required() )
) {
return;
}
global $wp_filter;
remove_filter( 'wp_resource_hints', 'rocket_dns_prefetch', 10, 2 );
add_filter( 'do_rocket_lazyload', '__return_false' );
add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
add_filter( 'pre_get_rocket_option_async_css', '__return_false' );
add_filter( 'pre_get_rocket_option_delay_js', '__return_false' );
add_filter( 'pre_get_rocket_option_preload_links', '__return_false' );
add_filter( 'pre_get_rocket_option_minify_js', '__return_false' );
add_filter( 'pre_get_rocket_option_minify_google_fonts', '__return_false' );
add_filter( 'pre_get_rocket_option_lazyload_css_bg_img', '__return_false' );
add_filter( 'pre_get_cloudflare_protocol_rewrite', '__return_false' );
add_filter( 'do_rocket_protocol_rewrite', '__return_false' );
unset( $wp_filter['rocket_buffer'] );
$options = get_option( self::AMP_OPTIONS, [] );
if ( ! empty( $options['theme_support'] )
&&
in_array( $options['theme_support'], [ 'transitional', 'reader' ], true ) ) {
add_filter( 'rocket_cdn_reject_files', [ $this, 'reject_files' ], PHP_INT_MAX );
add_filter( 'rocket_buffer', [ $this->cdn_subscriber, 'rewrite' ] );
add_filter( 'rocket_buffer', [ $this->cdn_subscriber, 'rewrite_srcset' ] );
}
}
/**
* Adds all CSS and JS files to the list of excluded CDN files.
*
* @since 3.5.5
*
* @param array $files List of excluded files.
* @return array List of excluded files.
*/
public function reject_files( $files ) {
return array_merge(
$files,
[
'(.*).css',
'(.*).js',
]
);
}
/**
* Adds the switching script from AMP to delay JS excluded files
*
* @since 3.11.1
*
* @param array $excluded List of excluded files.
* @return array List of excluded files.
*/
public function exclude_script_from_delay_js( $excluded ) {
$excluded[] = 'amp-mobile-version-switcher';
return $excluded;
}
}
@@ -0,0 +1,177 @@
<?php
declare( strict_types=1 );
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Autoptimize implements Subscriber_Interface {
/**
* WP Rocket Options instance
*
* @var Options_Data
*/
private $options;
/**
* Constructor
*
* @param Options_Data $options WP Rocket Options instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* Return an array of events that this subscriber listens to.
*
* @since 3.10.4
* @return array
*/
public static function get_subscribed_events() {
return [
'admin_notices' => [
[ 'warn_when_js_aggregation_and_delay_js_active' ],
[ 'warn_when_aggregate_inline_css_and_cpcss_active' ],
],
];
}
/**
* Add an admin warning notice when Delay JS and JS Aggregation are both activated.
*
* @since 3.10.4
*/
public function warn_when_js_aggregation_and_delay_js_active() {
if ( ! $this->can_notify() ) {
return;
}
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( ! (
'on' === get_option( 'autoptimize_js' )
&&
'on' === get_option( 'autoptimize_js_aggregate' )
) || false === (bool) $this->options->get( 'delay_js' )
) {
if ( ! is_array( $boxes ) ) {
return;
}
$this->remove_warning_dismissal( $boxes, __FUNCTION__ );
return;
}
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
$message = sprintf(
/* Translators: %1$s is an opening <strong> tag; %2$s is a closing </strong> tag */
__(
'%1$sWP Rocket: %2$sWe have detected that Autoptimize\'s JavaScript Aggregation feature is enabled. WP Rocket\'s Delay JavaScript Execution will not be applied to the file it creates. We suggest disabling %1$sJavaScript Aggregation%2$s to take full advantage of Delay JavaScript Execution.',
'rocket'
),
'<strong>',
'</strong>'
);
rocket_notice_html(
[
'status' => 'info',
'message' => $message,
'dismissible' => '',
'dismiss_button' => __FUNCTION__,
]
);
}
/**
* Add an admin warning notice when CPCSS and Aggregate Inline CSS are both activated.
*
* @since 3.10.4
*/
public function warn_when_aggregate_inline_css_and_cpcss_active() {
if ( ! $this->can_notify() ) {
return;
}
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( ! (
'on' === get_option( 'autoptimize_css' )
&&
'on' === get_option( 'autoptimize_css_aggregate' )
&&
'on' === get_option( 'autoptimize_css_include_inline' )
)
||
false === (bool) $this->options->get( 'async_css' )
) {
if ( ! is_array( $boxes ) ) {
return;
}
$this->remove_warning_dismissal( $boxes, __FUNCTION__ );
return;
}
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
$message = sprintf(
/* Translators: %1$s is an opening <strong> tag; %2$s is a closing </strong> tag */
__(
'%1$sWP Rocket: %2$sWe have detected that Autoptimize\'s Aggregate Inline CSS feature is enabled. WP Rocket\'s Load CSS Asynchronously will not work correctly. We suggest disabling %1$sAggregate Inline CSS%2$s to take full advantage of Load CSS Asynchronously Execution.',
'rocket'
),
'<strong>',
'</strong>'
);
rocket_notice_html(
[
'status' => 'info',
'message' => $message,
'dismissible' => '',
'dismiss_button' => __FUNCTION__,
]
);
}
/**
* Whether this compatibility can use notifications.
*
* @return bool
*/
private function can_notify() {
if ( 'settings_page_wprocket' !== get_current_screen()->id ) {
return false;
}
return rocket_get_constant( 'AUTOPTIMIZE_PLUGIN_VERSION', false )
&&
current_user_can( 'rocket_manage_options' );
}
/**
* Remove a warning box dismissal.
*
* @param array $boxes The rocket_boxes user meta.
* @param string $name Slug for the box to be removed.
*/
private function remove_warning_dismissal( $boxes, $name ) {
if ( ! in_array( $name, $boxes, true ) ) {
return;
}
unset( $boxes[ array_search( $name, $boxes, true ) ] );
update_user_meta( get_current_user_id(), 'rocket_boxes', $boxes );
}
}
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Ezoic implements Subscriber_Interface {
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_plugins_to_deactivate' => 'add_conflict',
'rocket_plugins_to_deactivate_explanations' => 'add_conflict_explanations',
];
}
/**
* Adds Ezoic plugin to plugins to deactivate array
*
* @param array $plugins List of recommended plugins to deactivate.
*
* @return array
*/
public function add_conflict( $plugins ) {
$plugins['ezoic'] = 'ezoic-integration/ezoic-integration.php';
return $plugins;
}
/**
* Adds explanation for deactivation recommendation
*
* @param array $plugins_explanations List of recommended plugins to deactivate explanations.
*
* @return array
*/
public function add_conflict_explanations( $plugins_explanations ) {
$plugins_explanations['ezoic'] = sprintf(
// translators: %1$s = opening <a> tag, %2$s = closing </a> tag.
__( 'This plugin blocks WP Rocket\'s caching and optimizations. Deactivate it and use %1$sEzoic\'s nameserver integration%2$s instead.', 'rocket' ),
'<a href="https://support.ezoic.com/kb/article/how-can-i-integrate-my-site-with-ezoic" target="_blank" rel="noopener noreferrer">',
'</a>'
);
return $plugins_explanations;
}
}
@@ -0,0 +1,295 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
use WP_Hummingbird_Settings;
use WP_Hummingbird_Utils;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Hummingbird compatibility class
*/
class Hummingbird implements Subscriber_Interface {
/**
* WP Rocket Options instance
*
* @var Options_Data
*/
private $options;
/**
* Array containing the errors
*
* @var array
*/
private $errors = [];
/**
* Constructor
*
* @param Options_Data $options WP Rocket Options instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.3.3
* @author Remy Perona
*
* @return array
*/
public static function get_subscribed_events() {
return [
'admin_notices' => 'warning_notice',
];
}
/**
* Display a notice if conflicting options are active
*
* @since 3.3.3
* @author Remy Perona
*
* @return void
*/
public function warning_notice() {
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
if ( ! is_plugin_active( 'hummingbird-performance/wp-hummingbird.php' ) && ! is_plugin_active( 'wp-hummingbird/wp-hummingbird.php' ) ) {
return;
}
$this->check_cache();
$this->check_assets();
$this->check_browser_caching();
$this->check_gzip();
$this->check_emoji();
if ( 0 === count( $this->errors ) ) {
return;
}
// Translators: %s = Plugin name.
$message = '<p>' . sprintf( _nx( 'Please deactivate the following %s option which conflicts with WP Rocket features:', 'Please deactivate the following %s options which conflict with WP Rocket features:', count( $this->errors ), 'Hummingbird notice', 'rocket' ), 'Hummingbird' ) . '</p>';
$message .= '<ul>';
foreach ( $this->errors as $error ) {
$message .= '<li>' . $error . '</li>';
}
$message .= '</ul>';
rocket_notice_html(
[
'status' => 'error',
'message' => $message,
]
);
}
/**
* Checks if the Hummingbird Utils class exists
*
* @since 3.3.3
* @author Remy Perona
*
* @return boolean
*/
private function is_utils_available() {
if ( ! class_exists( 'WP_Hummingbird_Utils' ) ) {
return false;
}
if ( ! method_exists( 'WP_Hummingbird_Utils', 'get_module' ) ) {
return false;
}
return true;
}
/**
* Checks if the Hummingbird settings class exists
*
* @since 3.3.3
* @author Remy Perona
*
* @return boolean
*/
private function is_settings_available() {
if ( ! class_exists( 'WP_Hummingbird_Settings' ) ) {
return false;
}
if ( ! method_exists( 'WP_Hummingbird_Settings', 'get_setting' ) ) {
return false;
}
return true;
}
/**
* Checks if Hummingbird and WP Rocket disable emoji options are active at the same time
*
* @since 3.3.3
* @author Remy Perona
*
* @return bool
*/
private function check_emoji() {
if ( ! $this->is_settings_available() ) {
return false;
}
if ( $this->options->get( 'emoji' ) && WP_Hummingbird_Settings::get_setting( 'emoji', 'advanced' ) ) {
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
$this->errors[] = sprintf( _x( '%1$s %2$sdisable emoji%3$s conflicts with WP Rockets %2$sdisable emoji%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
return true;
}
return false;
}
/**
* Checks if Hummingbird Gzip rules are in the htaccess file.
*
* @since 3.3.3
* @author Remy Perona
*
* @return bool
*/
private function check_gzip() {
if ( ! $this->is_utils_available() ) {
return false;
}
$gzip = WP_Hummingbird_Utils::get_module( 'gzip' );
if ( ! $gzip instanceof \WP_Hummingbird_Module_GZip ) {
return false;
}
if ( ! method_exists( $gzip, 'is_htaccess_written' ) ) {
return false;
}
if ( ! method_exists( $gzip, 'get_server_type' ) ) {
return false;
}
if ( $gzip::is_htaccess_written( 'gzip' ) && 'apache' === $gzip::get_server_type() ) {
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
$this->errors[] = sprintf( _x( '%1$s %2$sGZIP compression%3$s conflicts with WP Rocket %2$sGZIP compression%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
return true;
}
return false;
}
/**
* Checks if Hummingbird browser caching rules are in the htaccess file
*
* @since 3.3.3
* @author Remy Perona
*
* @return bool
*/
private function check_browser_caching() {
if ( ! $this->is_utils_available() ) {
return false;
}
$caching = WP_Hummingbird_Utils::get_module( 'caching' );
if ( ! $caching instanceof \WP_Hummingbird_Module_Caching ) {
return false;
}
if ( ! method_exists( $caching, 'is_htaccess_written' ) ) {
return false;
}
if ( ! method_exists( $caching, 'get_server_type' ) ) {
return false;
}
if ( $caching::is_htaccess_written( 'caching' ) && 'apache' === $caching::get_server_type() ) {
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
$this->errors[] = sprintf( _x( '%1$s %2$sbrowser caching%3$s conflicts with WP Rocket %2$sbrowser caching%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
return true;
}
return false;
}
/**
* Checks if Hummingbird Cache is active
*
* @since 3.3.3
* @author Remy Perona
*
* @return bool
*/
private function check_cache() {
if ( ! $this->is_utils_available() ) {
return false;
}
$cache = WP_Hummingbird_Utils::get_module( 'page_cache' );
if ( ! $cache instanceof \WP_Hummingbird_Module_Page_Cache ) {
return false;
}
if ( ! method_exists( $cache, 'is_active' ) ) {
return false;
}
if ( $cache->is_active() ) {
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
$this->errors[] = sprintf( _x( '%1$s %2$spage caching%3$s conflicts with WP Rocket %2$spage caching%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
return true;
}
return false;
}
/**
* Checks if Hummingbird Assets optimization is active
*
* Checks against WP Rocket Minify CSS, Minify JS and Defer JS options.
*
* @since 3.3.3
* @author Remy Perona
*
* @return bool
*/
private function check_assets() {
if ( ! $this->is_utils_available() ) {
return false;
}
$minify = WP_Hummingbird_Utils::get_module( 'minify' );
if ( ! $minify instanceof \WP_Hummingbird_Module_Minify ) {
return false;
}
if ( ! method_exists( $minify, 'is_active' ) ) {
return false;
}
if ( $minify->is_active() && ( $this->options->get( 'minify_css' ) || $this->options->get( 'minify_js' ) || $this->options->get( 'defer_all_js' ) ) ) {
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
$this->errors[] = sprintf( _x( '%1$s %2$sasset optimization%3$s conflicts with WP Rocket %2$sfile optimization%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
return true;
}
return false;
}
}
@@ -0,0 +1,61 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Perfmatters implements Subscriber_Interface {
/**
* Return an array of events that this subscriber listens to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! defined( 'PERFMATTERS_VERSION' ) ) {
return [];
}
return [
'rocket_disable_rucss_setting' => 'disable_rucss_setting',
'pre_get_rocket_option_remove_unused_css' => 'maybe_disable_rucss',
];
}
/**
* Disable RUCSS setting.
*
* @param array $status RUCSS option status.
* @return array
*/
public function disable_rucss_setting( array $status ): array {
if ( ! $this->is_perfmatters_rucss_active() ) {
return $status;
}
return [
'disable' => true,
'text' => __( 'Remove Unused CSS is currently activated in Perfmatters. If you want to use WP Rocket\'s Remove Unused CSS feature, disable this option in Perfmatters.', 'rocket' ),
];
}
/**
* Disable RUCSS option.
*
* @return bool|null
*/
public function maybe_disable_rucss() {
return $this->is_perfmatters_rucss_active() ? false : null;
}
/**
* Check if perfmatters rucss is active.
*
* @return bool
*/
private function is_perfmatters_rucss_active(): bool {
$perfmatters_options = get_option( 'perfmatters_options' );
return ! empty( $perfmatters_options['assets']['remove_unused_css'] );
}
}
@@ -0,0 +1,81 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
use WP_Rocket\Event_Management\Subscriber_Interface;
class RapidLoad implements Subscriber_Interface {
/**
* Return an array of events that this subscriber listens to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! defined( 'UUCSS_VERSION' ) ) {
return [];
}
return [
'rocket_disable_rucss_setting' => 'disable_rucss_setting',
'pre_get_rocket_option_remove_unused_css' => 'maybe_disable_rucss',
'deactivated_plugin' => [ 'rocket_clean_cache_on_deactivation', 12 ],
];
}
/**
* Disable RUCSS setting.
*
* @param array $status RUCSS option status.
* @return array
*/
public function disable_rucss_setting( array $status ): array {
if ( ! $this->is_rapidload_active() ) {
return $status;
}
return [
'disable' => true,
'text' => __( 'Automated unused CSS removal is currently activated in RapidLoad Power-Up for Autoptimize. If you want to use WP Rocket\'s Remove Unused CSS feature, disable the RapidLoad Power-Up for Autoptimize plugin.', 'rocket' ),
];
}
/**
* Disable RUCSS option.
*
* @return bool|null
*/
public function maybe_disable_rucss() {
return $this->is_rapidload_active() ? false : null;
}
/**
* Clean WP Rocket Cache when Rapidload is deactivated.
*
* @param string $plugin Plugin file.
* @return void
*/
public function rocket_clean_cache_on_deactivation( string $plugin ): void {
if ( ! $this->is_rapidload_active() ) {
return;
}
if ( 'unusedcss/unusedcss.php' !== $plugin ) {
return;
}
rocket_dismiss_box( 'rocket_warning_plugin_modification' );
rocket_clean_domain();
}
/**
* Check if RapidLoad Power-Up for Autoptimize is active.
*
* @return boolean
*/
private function is_rapidload_active(): bool {
$autoptimize_uucss_settings = get_option( 'autoptimize_uucss_settings' );
return ( isset( $autoptimize_uucss_settings['uucss_api_key_verified'] ) && 1 === $autoptimize_uucss_settings['uucss_api_key_verified'] && $autoptimize_uucss_settings['valid_domain'] );
}
}
@@ -0,0 +1,34 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
use WP_Rocket\Event_Management\Subscriber_Interface;
class RocketLazyLoad implements Subscriber_Interface {
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events(): array {
if ( ! defined( 'ROCKET_LL_VERSION' ) ) {
return [];
}
return [
'rocket_delay_js_exclusions' => 'exclude_rocket_lazyload_script',
];
}
/**
* Excludes rocket lazyload script from delay js.
*
* @param array $excluded List of excluded files.
*
* @return array
*/
public function exclude_rocket_lazyload_script( $excluded ): array {
$excluded[] = 'rocket-lazy-load/assets/js/\d\d\.\d/lazyload.min.js';
return $excluded;
}
}
@@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
use WP_Rocket\Event_Management\Subscriber_Interface;
class WPMeteor implements Subscriber_Interface {
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events(): array {
return [
'rocket_delay_js_settings_field' => 'maybe_disable_delay_js_field',
'activate_wp-meteor/wp-meteor.php' => 'disable_delay_js',
'wp_rocket_upgrade' => [ 'maybe_disable_delay_js', 10, 2 ],
'pre_update_option_wp_rocket_settings' => 'disable_delay_js_on_option_update',
];
}
/**
* Disable the delay JS field when WP Meteor is active
*
* @since 3.9.2
*
* @param array $field Delay JS field data array.
*
* @return array
*/
public function maybe_disable_delay_js_field( $field ): array {
if ( ! is_plugin_active( 'wp-meteor/wp-meteor.php' ) ) {
return $field;
}
$field['container_class'][] = 'wpr-isDisabled';
$field['value'] = 0;
$field['input_attr']['disabled'] = 1;
$field['helper'] = sprintf(
// translators: %1$s = plugin name.
__( 'Delay JS is currently activated in %1$s. If you want to use WP Rocket’s delay JS, disable %1$s', 'rocket' ),
'WP Meteor'
);
return $field;
}
/**
* Disable delay JS option when WP Meteor is activated
*
* @since 3.9.2
*
* @return void
*/
public function disable_delay_js() {
$options = get_option( 'wp_rocket_settings', [] );
$options['delay_js'] = 0;
update_option( 'wp_rocket_settings', $options );
}
/**
* Disable delay JS when updating to 3.9.2 and above and WP Meteor is active
*
* @since 3.9.2
*
* @param string $new_version Plugin new version.
* @param string $old_version Plugin old version.
*
* @return void
*/
public function maybe_disable_delay_js( $new_version, $old_version ) {
if ( version_compare( $old_version, '3.9.2', '>' ) ) {
return;
}
if ( ! is_plugin_active( 'wp-meteor/wp-meteor.php' ) ) {
return;
}
$this->disable_delay_js();
}
/**
* Disable delay JS on WP Rocket settings update if WP Meteor is active
*
* @since 3.9.2
*
* @param mixed $value The new, unserialized option value.
*
* @return mixed
*/
public function disable_delay_js_on_option_update( $value ) {
if ( ! is_plugin_active( 'wp-meteor/wp-meteor.php' ) ) {
return $value;
}
if ( ! isset( $value['delay_js'] ) ) {
return $value;
}
if ( 0 === (int) $value['delay_js'] ) {
return $value;
}
$value['delay_js'] = 0;
return $value;
}
}
@@ -0,0 +1,102 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with PDF Embedder Free / Premium / Secure plugin.
*
* @since 3.6.2
*/
class PDFEmbedder implements Subscriber_Interface {
/**
* Subscribed events.
*
* @since 3.6.2
*/
public static function get_subscribed_events() {
// All 3 plugins use the same core class.
if ( ! class_exists( 'core_pdf_embedder' ) ) {
return [];
}
return [
'rocket_exclude_js' => 'exclude_pdfembedder_scripts',
];
}
/**
* Adds PDFEmbedder scripts to defer JS exclusion
*
* @since 3.6.2
*
* @param array $excluded_js Array of scripts to exclude.
* @return array
*/
public function exclude_pdfembedder_scripts( $excluded_js ) {
if (
class_exists( 'PDF_Embedder_Basic' )
||
class_exists( 'pdfemb_basic_pdf_embedder' )
) {
// Exclude Free version.
return array_merge(
$excluded_js,
$this->pdfembedder_free_scripts()
);
}
if ( class_exists( 'pdfemb_premium_mobile_pdf_embedder' ) ) {
// Excludes PDFEmbedder-premium.
return array_merge(
$excluded_js,
$this->pdfembedder_premium_scripts()
);
}
if ( class_exists( 'pdfemb_premium_secure_pdf_embedder' ) ) {
// Excludes PDFEmbedder-premium-secure.
return array_merge(
$excluded_js,
$this->pdfembedder_secure_scripts()
);
}
return $excluded_js;
}
/**
* PDFEmbedder Free JS scripts.
*
* @return array JS files to be excluded.
*/
private function pdfembedder_free_scripts() {
return [
rocket_clean_exclude_file( plugins_url( '/pdf-embedder/js/(.*).js' ) ),
];
}
/**
* PDFEmbedder Premium JS scripts.
*
* @return array JS files to be excluded.
*/
private function pdfembedder_premium_scripts() {
return [
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium/js/pdfjs/(.*).js' ) ),
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium/js/(.*).js' ) ),
];
}
/**
* PDFEmbedder Secure JS scripts.
*
* @return array JS files to be excluded.
*/
private function pdfembedder_secure_scripts() {
return [
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium-secure/js/pdfjs/(.*).js' ) ),
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium-secure/js/(.*).js' ) ),
];
}
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
class PWA implements Subscriber_Interface {
/**
* Subscribed events.
*/
public static function get_subscribed_events() {
return [
'rocket_cache_reject_uri' => 'exclude_service_worker',
];
}
/**
* Excludes the PWA service worker URL
*
* @param array $excluded Array of excluded URLs.
*
* @return array
*/
public function exclude_service_worker( $excluded ): array {
if ( ! function_exists( 'wp_get_service_worker_url' ) ) {
return $excluded;
}
$excluded[] = '/wp.serviceworker/?';
return $excluded;
}
}
@@ -0,0 +1,35 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\PageBuilder;
use WP_Rocket\Event_Management\Subscriber_Interface;
class BeaverBuilder implements Subscriber_Interface {
/**
* Events this subscriber listens to
*
* @inheritDoc
*/
public static function get_subscribed_events() {
if ( ! rocket_get_constant( 'FL_BUILDER_VERSION' ) ) {
return [];
}
return [
'fl_builder_before_save_layout' => 'purge_cache',
'fl_builder_cache_cleared' => 'purge_cache',
];
}
/**
* Purge the cache when the beaver builder layout is updated to update the minified files content & URL
*
* Previously rocket_beaver_builder_clean_domain()
*
* @since 3.6
* @author Remy Perona
*/
public function purge_cache() {
rocket_clean_minify();
rocket_clean_domain();
}
}
@@ -0,0 +1,208 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins\PageBuilder;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
/**
* Compatibility file for Elementor plugin
*/
class Elementor implements Subscriber_Interface {
/**
* WP Rocket options.
*
* @var Options_Data
*/
private $options;
/**
* WP_Filesystem_Direct instance.
*
* @var \WP_Filesystem_Direct
*/
private $filesystem;
/**
* Delay JS HTML class.
*
* @var HTML
*/
private $delayjs_html;
/**
* Constructor
*
* @param Options_Data $options WP Rocket options.
* @param \WP_Filesystem_Direct $filesystem The Filesystem object.
* @param HTML $delayjs_html DelayJS HTML class.
*/
public function __construct( Options_Data $options, $filesystem, HTML $delayjs_html ) {
$this->options = $options;
$this->filesystem = $filesystem;
$this->delayjs_html = $delayjs_html;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
return [];
}
return [
'wp_rocket_loaded' => 'remove_widget_callback',
'rocket_exclude_css' => 'exclude_post_css',
'elementor/core/files/clear_cache' => 'clear_cache',
'elementor/maintenance_mode/mode_changed' => 'clear_cache',
'update_option__elementor_global_css' => 'clear_cache',
'delete_option__elementor_global_css' => 'clear_cache',
'rocket_buffer' => [ 'add_fix_animation_script', 28 ],
'rocket_exclude_js' => 'exclude_js',
'rocket_skip_post_row_actions' => 'remove_rocket_option',
'rocket_metabox_options_post_types' => 'remove_rocket_option',
'rocket_skip_admin_bar_cache_purge_option' => [ 'skip_admin_bar_option', 1, 2 ],
'rocket_submitbox_options_post_types' => 'remove_rocket_option',
'rocket_skip_admin_bar_clear_used_css_option' => [ 'skip_admin_bar_option', 1, 2 ],
];
}
/**
* Remove the callback to clear the cache on widget update
*
* @return void
*/
public function remove_widget_callback() {
remove_filter( 'widget_update_callback', 'rocket_widget_update_callback' );
}
/**
* Clear WP Rocket caches when Elementor changes the CSS
*
* @return void
*/
public function clear_cache() {
if ( ! $this->elementor_use_external_file() ) {
return;
}
rocket_clean_domain();
rocket_clean_minify( 'css' );
}
/**
* Checks whether elementor is set use external CSS file or not.
*
* @return bool
*/
private function elementor_use_external_file() {
return 'internal' !== get_option( 'elementor_css_print_method' );
}
/**
* Add Fix Elementor Pro animations script.
*
* @since 3.9.2
*
* @param string $html HTML content.
*
* @return string HTML with Fix Elementor Pro animations script.
*/
public function add_fix_animation_script( $html ) {
if ( ! $this->delayjs_html->is_allowed() ) {
return $html;
}
$pattern = '/<\/body*>/i';
$fix_elementor_animation_script = $this->filesystem->get_contents( rocket_get_constant( 'WP_ROCKET_PATH' ) . 'assets/js/elementor-animation.js' );
if ( false !== $fix_elementor_animation_script ) {
$html = preg_replace( $pattern, "<script>{$fix_elementor_animation_script}</script>$0", $html, 1 );
}
return $html;
}
/**
* Excludes Elementor CSS from minify/combine
*
* @since 3.10.9
*
* @param array $excluded Array of excluded patterns.
*
* @return array
*/
public function exclude_post_css( $excluded ): array {
if ( ! $this->elementor_use_external_file() ) {
return $excluded;
}
$upload = wp_get_upload_dir();
$basepath = wp_parse_url( $upload['baseurl'], PHP_URL_PATH );
if ( empty( $basepath ) ) {
return $excluded;
}
$excluded[] = $basepath . '/elementor/css/(.*).css';
return $excluded;
}
/**
* Excludes JS files from minify/combine JS
*
* @since 3.10.9
*
* @param array $excluded_files Array of excluded patterns.
*
* @return array
*/
public function exclude_js( $excluded_files ): array {
if ( ! $this->options->get( 'minify_concatenate_js', false ) ) {
return $excluded_files;
}
$excluded_files[] = '/wp-includes/js/dist/hooks(.min)?.js';
return $excluded_files;
}
/**
* Remove rocket metabox option from post.
*
* @param array $cpts Custom post type.
* @return array
*/
public function remove_rocket_option( array $cpts ): array {
if ( isset( $cpts['elementor_library'] ) ) {
unset( $cpts['elementor_library'] );
}
return $cpts;
}
/**
* Remove cache or purge option from elementor template post.
*
* @param boolean $should_skip Should skip rocket option to admin bar.
* @param mixed $post Post object.
* @return boolean
*/
public function skip_admin_bar_option( bool $should_skip, $post ): bool {
if ( null === $post ) {
return $should_skip;
}
if ( 'elementor_library' === $post->post_type ) {
return true;
}
return $should_skip;
}
}
@@ -0,0 +1,48 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use Smush\Core\Settings;
use WP_Rocket\Admin\Options;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with RevolutionSlider.
*
* @since 3.9.2
*/
class RevolutionSlider implements Subscriber_Interface {
/**
* Subscribed events for RevolutionSlider.
*
* @since 3.9.2
*
* @inheritDoc
*/
public static function get_subscribed_events() {
if ( ! defined( 'RS_REVISION' ) || version_compare( RS_REVISION, '6.5.5', '<' ) ) {
return [];
}
return [
'rocket_exclude_defer_js' => 'exclude_defer_js',
];
}
/**
* Excludes jquery and jquery migrate JS files from defer JS
*
* @since 3.9.2
*
* @param array $exclude_defer_js Array of JS file paths 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[] = '/jquery-migrate(.min)?.js';
return $exclude_defer_js;
}
}
@@ -0,0 +1,74 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\SEO;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
class AllInOneSEOPack implements Subscriber_Interface {
/**
* Option instance.
*
* @var Options_Data
*/
protected $option;
/**
* Instantiate class.
*
* @param Options_Data $option Option instance.
*/
public function __construct( Options_Data $option ) {
$this->option = $option;
}
/**
* Subscribed events.
*/
public static function get_subscribed_events() {
$aioseo_v3 = defined( 'AIOSEOP_VERSION' );
$aioseo_v4 = defined( 'AIOSEO_VERSION' ) && function_exists( 'aioseo' );
if ( ! $aioseo_v3 && ! $aioseo_v4 ) {
return [];
}
return [
'rocket_sitemap_preload_list' => [ 'add_all_in_one_seo_sitemap', 15 ],
];
}
/**
* Add All in One SEO Sitemap to the preload list
*
* @param Array $sitemaps Array of sitemaps to preload.
* @return Array Updated array of sitemaps to preload
*/
public function add_all_in_one_seo_sitemap( $sitemaps ) {
$aioseo_v3 = defined( 'AIOSEOP_VERSION' );
$aioseo_v4 = defined( 'AIOSEO_VERSION' ) && function_exists( 'aioseo' );
$sitemap_enabled = false;
if ( $aioseo_v3 && ! $aioseo_v4 ) {
$aioseop_options = get_option( 'aioseop_options' );
$sitemap_enabled = ( isset( $aioseop_options['modules']['aiosp_feature_manager_options']['aiosp_feature_manager_enable_sitemap'] ) && 'on' === $aioseop_options['modules']['aiosp_feature_manager_options']['aiosp_feature_manager_enable_sitemap'] ) || ( ! isset( $aioseop_options['modules']['aiosp_feature_manager_options'] ) && isset( $aioseop_options['modules']['aiosp_sitemap_options'] ) );
}
if (
( ! $aioseo_v4 && ! $sitemap_enabled ) ||
( $aioseo_v4 && ! aioseo()->options->sitemap->general->enable )
) {
return $sitemaps;
}
if ( $aioseo_v3 ) {
$sitemaps[] = trailingslashit( home_url() ) . apply_filters( 'aiosp_sitemap_filename', 'sitemap' ) . '.xml'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
} elseif ( $aioseo_v4 ) {
$sitemaps[] = trailingslashit( home_url() ) . apply_filters( 'aioseo_sitemap_filename', 'sitemap' ) . '.xml'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}
return $sitemaps;
}
}
@@ -0,0 +1,54 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\SEO;
use RankMath\Helper;
use RankMath\Sitemap\Router;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
class RankMathSEO implements Subscriber_Interface {
/**
* Options instance.
*
* @var Options_Data
*/
protected $option;
/**
* Instantiate class.
*
* @param Options_Data $option Options instance.
*/
public function __construct( Options_Data $option ) {
$this->option = $option;
}
/**
* Subscribed events.
*/
public static function get_subscribed_events() {
if ( ! defined( 'RANK_MATH_FILE' ) || ! Helper::is_module_active( 'sitemap' ) ) {
return [];
}
return [
'rocket_sitemap_preload_list' => [ 'rocket_sitemap', 15 ],
];
}
/**
* Add SEO sitemap URL to the sitemaps to preload
*
* @param array $sitemaps Sitemaps to preload.
* @return array Updated Sitemaps to preload
*/
public function rocket_sitemap( $sitemaps ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$sitemaps[] = Router::get_base_url( 'sitemap_index.xml' );
return $sitemaps;
}
}
@@ -0,0 +1,54 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\SEO;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
class SEOPress implements Subscriber_Interface {
/**
* Option instance.
*
* @var Options_Data
*/
protected $option;
/**
* Instantiate class.
*
* @param Options_Data $option Option instance.
*/
public function __construct( Options_Data $option ) {
$this->option = $option;
}
/**
* Subscribed events.
*/
public static function get_subscribed_events() {
if ( ! function_exists( 'seopress_get_toggle_option' ) || 1 !== (int) seopress_get_toggle_option( 'xml-sitemap' ) ) {
return [];
}
if ( ! method_exists( seopress_get_service( 'SitemapOption' ), 'isEnabled' ) || 1 !== (int) seopress_get_service( 'SitemapOption' )->isEnabled() ) {
return [];
}
return [
'rocket_sitemap_preload_list' => [ 'add_seopress_sitemap', 15 ],
];
}
/**
* Add SEOPress sitemap URL to the sitemaps to preload
*
* @param array $sitemaps Sitemaps to preload.
* @return array Updated Sitemaps to preload
*/
public function add_seopress_sitemap( $sitemaps ) {
$sitemaps[] = get_home_url() . '/sitemaps.xml';
return $sitemaps;
}
}
@@ -0,0 +1,86 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\SEO;
use The_SEO_Framework\Bridges\Sitemap;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
class TheSEOFramework implements Subscriber_Interface {
/**
* Option instance.
*
* @var Options_Data
*/
protected $option;
/**
* Instantiate the class.
*
* @param Options_Data $option Option instance.
*/
public function __construct( Options_Data $option ) {
$this->option = $option;
}
/**
* Subscribed events.
*/
public static function get_subscribed_events() {
if ( ! function_exists( 'the_seo_framework' ) ) {
return [];
}
$tsf = the_seo_framework();
// Either TSF < 3.1, or the plugin's silenced (soft-disabled) via a drop-in.
if ( empty( $tsf->loaded ) ) {
return [];
}
/**
* 1. Performs option & other checks.
* 2. Checks for conflicting sitemap plugins that might prevent loading.
*
* These methods cache their output at runtime.
*
* @link https://github.com/wp-media/wp-rocket/issues/899
*/
if ( ! $tsf->can_run_sitemap() ) {
return [];
}
return [
'rocket_sitemap_preload_list' => [ 'add_tsf_sitemap_to_preload', 15 ],
];
}
/**
* Adds TSF sitemap URLs to preload.
*
* @param array $sitemaps Sitemaps to preload.
* @return array Updated Sitemaps to preload
*/
public function add_tsf_sitemap_to_preload( $sitemaps ) {
// The autoloader in TSF doesn't check for file_exists(). So, use version compare instead to prevent fatal errors.
if ( version_compare( rocket_get_constant( 'THE_SEO_FRAMEWORK_VERSION', false ), '4.0', '>=' ) ) {
// TSF 4.0+. Expect the class to exist indefinitely.
$sitemap_bridge = Sitemap::get_instance();
foreach ( $sitemap_bridge->get_sitemap_endpoint_list() as $id => $data ) {
// When the sitemap is good enough for a robots display, we determine it as valid for precaching.
// Non-robots display types are among the stylesheet endpoint, or the Yoast SEO-compatible endpoint.
// In other words, this enables support for ALL current and future public sitemap endpoints.
if ( ! empty( $data['robots'] ) ) {
$sitemaps[] = $sitemap_bridge->get_expected_sitemap_endpoint_url( $id );
}
}
} else {
// Deprecated. TSF <4.0.
$sitemaps[] = the_seo_framework()->get_sitemap_xml_url();
}
return $sitemaps;
}
}
@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Plugins\SEO;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Yoast implements Subscriber_Interface {
/**
* Options Data instance
*
* @var Options_Data
*/
private $options;
/**
* Constructor
*
* @param Options_Data $options Options_Data instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* Array of events this subscriber listens to
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_sitemap_preload_list' => [ 'add_sitemap', 15 ],
];
}
/**
* Add Yoast SEO sitemap URL to the sitemaps to preload
*
* @since 2.8
*
* @param array $sitemaps An array of sitemaps to preload.
*
* @return array
*/
public function add_sitemap( $sitemaps ): array {
if ( ! is_array( $sitemaps ) ) {
$sitemaps = (array) $sitemaps;
}
if ( ! $this->is_sitemap_enabled() ) {
return $sitemaps;
}
if ( ! class_exists( 'WPSEO_Sitemaps_Router' ) ) {
return $sitemaps;
}
$sitemaps[] = \WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' );
return $sitemaps;
}
/**
* Checks if sitemap is enabled in Yoast SEO
*
* @since 3.11.1
*
* @return bool
*/
private function is_sitemap_enabled(): bool {
static $enabled = null;
if ( ! is_null( $enabled ) ) {
return $enabled;
}
if ( ! rocket_has_constant( 'WPSEO_VERSION' ) ) {
$enabled = false;
return $enabled;
}
$yoast_seo_xml = get_option( 'wpseo_xml', [] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
if ( version_compare( rocket_get_constant( 'WPSEO_VERSION', '' ), '7.0' ) >= 0 ) {
$yoast_seo = get_option( 'wpseo', [] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$yoast_seo_xml['enablexmlsitemap'] = isset( $yoast_seo['enable_xml_sitemap'] ) && $yoast_seo['enable_xml_sitemap']; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}
$enabled = (bool) $yoast_seo_xml['enablexmlsitemap'];
return $enabled;
}
}
@@ -0,0 +1,134 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins\Security;
use WP_Rocket\Event_Management\Subscriber_Interface;
use wordfence;
use wfConfig;
/**
* Compatibility file for WordFence plugin
*
* @since 3.10
*/
class WordFenceCompatibility implements Subscriber_Interface {
/**
* Whitelisted_IPS.
*/
const WHITELISTED_IPS = [ '141.94.254.72' ];
/**
* Old Whitelisted IP.
*
* @var string
*/
private $old_rucss_ip = '135.125.83.227';
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.10
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! defined( 'WORDFENCE_VERSION' ) ) {
return [];
}
return [
'init' => [ 'whitelist_wordfence_firewall_ips', 11 ],
'rocket_deactivation' => 'pop_ip_from_whitelist',
];
}
/**
* Removes old ip from whitelist.
*
* @param string $old_rucss_ip Old RUCSS IP.
* @return void
*/
public function pop_old_ip( string $old_rucss_ip ) {
$whitelist = $this->can_pop_ip( $old_rucss_ip );
if ( ! $whitelist ) {
return;
}
// Update whitelist.
wfConfig::set( 'whitelisted', implode( ',', $whitelist ) );
}
/**
* Remove ip from whitelist.
*
* @return void
*/
public function pop_ip_from_whitelist() {
$whitelist = $this->can_pop_ip( self::WHITELISTED_IPS[0] );
if ( ! $whitelist ) {
return;
}
// Update whitelist.
wfConfig::set( 'whitelisted', implode( ',', $whitelist ) );
}
/**
* Check if ip can be removed.
*
* @param string $ip IP.
* @return array
*/
private function can_pop_ip( string $ip ) {
// Get all whitelists.
$whitelists = wfConfig::get( 'whitelisted', '' );
// Convert to array.
$whitelist_array = explode( ',', $whitelists );
// Get ip index.
$ip = array_search( $ip, $whitelist_array, true );
if ( false === $ip ) {
return false;
}
// Remove ip from whitelist.
unset( $whitelist_array[ $ip ] );
return $whitelist_array;
}
/**
* Whitelist wp-rocket ips in wordfence firewall
*
* @since 3.10
*
* @return void
*/
public function whitelist_wordfence_firewall_ips() {
// Pop old rucss ip.
$this->pop_old_ip( $this->old_rucss_ip );
/**
* Rocket wordfence whitelisted ips filter which adds IPs to wordfence whitelist.
*
* @since 3.10
*
* @param array list of IPs should be whitelisted
*/
$ips = apply_filters( 'rocket_wordfence_whitelisted_ips', self::WHITELISTED_IPS );
if ( empty( $ips ) ) {
return;
}
foreach ( $ips as $ip ) {
wordfence::whitelistIP( $ip );
}
}
}
@@ -0,0 +1,117 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Engine\Optimization\CSSTrait;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with Simple Custom CSS plugin.
*
* @since 3.6
* @author Soponar Cristina
*/
class SimpleCustomCss implements Subscriber_Interface {
use CSSTrait;
const FILENAME = 'sccss.css';
/**
* Base cache busting folder path
*
* @var string
*/
private $cache_busting_path;
/**
* SCCSS cache busting file path
*
* @var string
*/
private $filepath;
/**
* SCCSS cache busting file URL
*
* @var string
*/
private $file_url;
/**
* Constructor
*
* @param string $cache_busting_path Base cache busting folder path.
* @param string $cache_busting_url Base cache busting URL.
*/
public function __construct( $cache_busting_path, $cache_busting_url ) {
$blog_id = get_current_blog_id();
$this->cache_busting_path = $cache_busting_path . $blog_id . '/';
$this->filepath = $this->cache_busting_path . self::FILENAME;
$this->file_url = $cache_busting_url . $blog_id . '/' . self::FILENAME;
}
/**
* Subscribed events for AMP.
*
* @since 3.5.3
* @author Soponar Cristina
* @inheritDoc
*/
public static function get_subscribed_events() {
if ( ! defined( 'SCCSS_FILE' ) ) {
return [];
}
return [
'wp_enqueue_scripts' => [ 'cache_sccss', 98 ],
'update_option_sccss_settings' => 'update_cache_file',
];
}
/**
* Caches SCCSS code & remove the default enqueued URL
*
* @since 2.9
* @author Remy Perona
*/
public function cache_sccss() {
if ( ! rocket_direct_filesystem()->exists( $this->filepath ) ) {
$this->create_cache_file();
}
// This filter is documented in inc/Engine/Optimization/CSS/AbstractCSSOptimization.php.
wp_enqueue_style( 'scss', apply_filters( 'rocket_css_url', $this->file_url ), '', rocket_direct_filesystem()->mtime( $this->filepath ) );
remove_action( 'wp_enqueue_scripts', 'sccss_register_style', 99 );
}
/**
* Deletes & recreates cache for SCCSS code
*
* @since 3.6
* @author Remy Perona
*/
public function update_cache_file() {
rocket_clean_domain();
$this->create_cache_file();
}
/**
* Creates cache file for SCCSS code if it does not exist.
*
* @since 2.9
* @author Remy Perona
*
* @return bool Returns bool if the files exists or could not be created.
*/
private function create_cache_file() {
$options = get_option( 'sccss_settings' );
$raw_content = isset( $options['sccss-content'] ) ? $options['sccss-content'] : '';
$content = wp_kses( $raw_content, [ '\'', '\"' ] );
$content = str_replace( '&gt;', '>', $content );
$content = $this->apply_font_display_swap( $content );
if ( ! rocket_direct_filesystem()->is_dir( $this->cache_busting_path ) ) {
rocket_mkdir_p( $this->cache_busting_path );
}
return rocket_put_content( $this->filepath, $content );
}
}
@@ -0,0 +1,192 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use Smush\Core\Settings;
use WP_Rocket\Admin\Options;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with Smush
*
* @since 3.4.2
* @author Soponar Cristina
*/
class Smush implements Subscriber_Interface {
/**
* WP Options API instance
*
* @var Options
*/
private $options_api;
/**
* Options instance
*
* @var Options_Data
*/
private $options;
/**
* Subscribed events for Smush.
*
* @since 3.4.2
* @author Soponar Cristina
* @inheritDoc
*/
public static function get_subscribed_events() {
if ( ! rocket_has_constant( 'WP_SMUSH_VERSION' ) ) {
return [
'activate_wp-smushit/wp-smush.php' => [ 'maybe_deactivate_rocket_lazyload', 10 ],
];
}
return [
'update_option_wp-smush-settings' => [ 'maybe_deactivate_rocket_lazyload', 11 ],
'update_site_option_wp-smush-settings' => [ 'maybe_deactivate_rocket_lazyload', 11 ],
'update_option_wp-smush-lazy_load' => [ 'maybe_deactivate_rocket_lazyload', 11 ],
'update_site_option_wp-smush-lazy_load' => [ 'maybe_deactivate_rocket_lazyload', 11 ],
'rocket_maybe_disable_lazyload_helper' => 'is_smush_lazyload_active',
'rocket_maybe_disable_iframes_lazyload_helper' => 'is_smush_iframes_lazyload_active',
];
}
/**
* Constructor.
*
* @since 3.5.5
*
* @param Options $options_api WP Options API instance.
* @param Options_Data $options WP Rocket Options instance.
*/
public function __construct( Options $options_api, Options_Data $options ) {
$this->options_api = $options_api;
$this->options = $options;
}
/**
* Disable WP Rocket lazyload when activating WP Smush and values are already in the database.
*
* @since 3.4.2
* @author Soponar Cristina
*/
public function maybe_deactivate_rocket_lazyload() {
$enabled = $this->is_smush_lazyload_enabled();
$updated = false;
if ( $enabled['images'] && $this->options->get( 'lazyload' ) ) {
$this->options->set( 'lazyload', 0 );
$updated = true;
}
if ( $enabled['iframes'] && $this->options->get( 'lazyload_iframes' ) ) {
$this->options->set( 'lazyload_iframes', 0 );
$updated = true;
}
if ( ! $updated ) {
return;
}
$this->options_api->set( 'settings', $this->options->get_options() );
}
/**
* Add "Smush" to the provided array if WP Smush lazyload is enabled for images.
*
* @since 3.4.2
* @author Soponar Cristina
*
* @param array $disable_images_lazyload Array with plugins which disable lazyload functionality.
* @return array A list of plugin names.
*/
public function is_smush_lazyload_active( array $disable_images_lazyload ) {
$enabled = $this->is_smush_lazyload_enabled();
if ( $enabled['images'] ) {
$disable_images_lazyload[] = __( 'Smush', 'rocket' );
}
return $disable_images_lazyload;
}
/**
* Add "Smush" to the provided array if WP Smush lazyload is enabled for iframes.
*
* @since 3.5.5
*
* @param array $disable_iframes_lazyload Array with plugins which disable lazyload functionality.
* @return array A list of plugin names.
*/
public function is_smush_iframes_lazyload_active( $disable_iframes_lazyload ) {
$enabled = $this->is_smush_lazyload_enabled();
if ( $enabled['iframes'] ) {
$disable_iframes_lazyload[] = __( 'Smush', 'rocket' );
}
return $disable_iframes_lazyload;
}
/**
* Tell if Smush’s lazyload is enabled for each type of content.
*
* @since 3.5.5
*
* @return array {
* @var bool $images True when lazyload is enabled for images. False otherwise.
* @var bool $iframes True when lazyload is enabled for iframes. False otherwise.
* }
*/
private function is_smush_lazyload_enabled() {
$enabled = [
'images' => false,
'iframes' => false,
];
if ( ! class_exists( '\Smush\Core\Settings' ) ) {
return $enabled;
}
if ( ! method_exists( '\Smush\Core\Settings', 'get_instance' ) ) {
return $enabled;
}
$smush_settings = Settings::get_instance();
if ( ! method_exists( $smush_settings, 'get' ) || ! method_exists( $smush_settings, 'get_setting' ) ) {
return $enabled;
}
if ( ! $smush_settings->get( 'lazy_load' ) ) {
return $enabled;
}
$formats = $smush_settings->get_setting( 'wp-smush-lazy_load' );
$formats = ! empty( $formats['format'] ) && is_array( $formats['format'] ) ? array_filter( $formats['format'] ) : [];
$image_formats = array_intersect_key(
$formats,
// Allowlist image formats.
[
'jpeg' => false,
'png' => false,
'gif' => false,
'svg' => false,
]
);
if ( ! empty( $image_formats ) ) {
// One or several image formats are enabled in Smush.
$enabled['images'] = true;
}
if ( ! empty( $formats['iframe'] ) ) {
// Iframe is enabled in Smush.
$enabled['iframes'] = true;
}
return $enabled;
}
}
@@ -0,0 +1,44 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with the Events Calendar.
*/
class TheEventsCalendar implements Subscriber_Interface {
/**
* Subscribed events for The Events Calendar.
*/
public static function get_subscribed_events() {
if ( ! rocket_get_constant( 'TRIBE_EVENTS_FILE', false ) ) {
return [];
}
return [
'rocket_preload_exclude_urls' => 'exclude_from_preload_calendars',
];
}
/**
* Exclude calendars from the preload.
*
* @param array $excluded excluded urls.
* @return array
*/
public function exclude_from_preload_calendars( $excluded ) {
if ( ! function_exists( 'tribe_get_option' ) ) {
return $excluded;
}
$uri = tribe_get_option( 'eventsSlug', 'event' );
$excluded[] = "/$uri/20(.*)";
return $excluded;
}
}
@@ -0,0 +1,50 @@
<?php
declare( strict_types=1 );
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
class ThirstyAffiliates implements Subscriber_Interface {
/**
* Returns an array of events this subscriber listens to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_preload_links_exclusions' => [ 'exclude_link_prefix', PHP_INT_MAX, 2 ],
];
}
/**
* Excludes the link prefix from preload links
*
* @since 3.10.8
*
* @param string[] $excluded Array of excluded patterns.
* @param string[] $default Array of default excluded patterns.
*
* @return array
*/
public function exclude_link_prefix( $excluded, $default ): array {
if ( ! is_array( $excluded ) ) {
$excluded = (array) $excluded;
}
if ( ! is_plugin_active( 'thirstyaffiliates/thirstyaffiliates.php' ) ) {
return $excluded;
}
$excluded = array_diff( $excluded, $default );
$link_prefix = get_option( 'ta_link_prefix', 'recommends' );
if ( 'custom' === $link_prefix ) {
$link_prefix = get_option( 'ta_link_prefix_custom', 'recommends' );
}
$excluded[] = '/' . $link_prefix . '/';
return $excluded;
}
}
@@ -0,0 +1,37 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with Unlimited Elements.
*/
class UnlimitedElements implements Subscriber_Interface {
/**
* Subscriber for Unlimited Elements.
*
* @return array
*/
public static function get_subscribed_events() {
if ( ! defined( 'UNLIMITED_ELEMENTS_INC' ) ) {
return [];
}
return [ 'rocket_rucss_inline_content_exclusions' => 'exclude_inline_from_rucss' ];
}
/**
* Exclude inline style from RUCSS.
*
* @param array $excluded excluded css.
* @return array
*/
public function exclude_inline_from_rucss( $excluded ) {
$excluded[] = '#uc_';
return $excluded;
}
}
@@ -0,0 +1,118 @@
<?php
namespace WP_Rocket\ThirdParty\Plugins;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class WPGeotargeting implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
$events = [
'geotWP/activated' => [ 'activate_geotargetingwp', 11 ],
'geotWP/deactivated' => [ 'deactivate_geotargetingwp', 11 ],
];
if ( ! class_exists( '\GeotWP\GeotargetingWP' ) ) {
return $events;
}
$events['rocket_htaccess_mod_rewrite'] = [ 'return_false', 72 ];
$events['rocket_cache_dynamic_cookies'] = 'add_geot_cookies';
$events['rocket_cache_mandatory_cookies'] = 'add_geot_cookies';
$events['geot/pass_basic_rules'] = [ 'maybe_disable_rules', 10, 3 ];
if ( ! get_option( 'geotWP-deactivated' ) ) {
return $events;
}
// Update the WP Rocket rules on the .htaccess file.
$events['admin_init'] = [
[ 'flush_rocket_htaccess' ],
[ 'rocket_generate_config_file' ],
];
delete_option( 'geotWP-deactivated' );
return $events;
}
/**
* Disable rules on nowprocket parameter.
*
* @param bool $bool Is Disabled.
* @param array $opts Options.
* @param string $current_url Current URL.
* @return bool
*/
public function maybe_disable_rules( $bool, $opts, $current_url ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.boolFound
$query = wp_parse_url( $current_url, PHP_URL_QUERY );
return ! str_contains( $query ? $query : '', 'nowprocket' );
}
/**
* Add cookies when we activate any goetargetingWP plugin.
*
* @author Damian Logghe
*/
public function activate_geotargetingwp() {
add_filter( 'rocket_htaccess_mod_rewrite', [ $this, 'return_false' ], 72 );
add_filter( 'rocket_cache_dynamic_cookies', [ $this, 'add_geot_cookies' ] );
add_filter( 'rocket_cache_mandatory_cookies', [ $this, 'add_geot_cookies' ] );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
/**
* Remove cookies when we deactivate the plugin.
*
* @author Damian Logghe
*/
public function deactivate_geotargetingwp() {
// add into db a record saying we deactivated one of the family plugins.
update_option( 'geotWP-deactivated', true );
remove_filter( 'rocket_htaccess_mod_rewrite', [ $this, 'return_false' ], 72 );
remove_filter( 'rocket_cache_dynamic_cookies', [ $this, 'add_geot_cookies' ] );
remove_filter( 'rocket_cache_mandatory_cookies', [ $this, 'add_geot_cookies' ] );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
/**
* Let users modify cache level by default set to country.
*
* @author Damian Logghe
*
* @param array $cookies An array of cookies.
* @return array Updated array of cookies
*/
public function add_geot_cookies( $cookies ) {
/**
* Geotargeting cookies.
*
* @param array $types Types from cookies (country, state, city).
* @return array
*/
$enabled_cookies = apply_filters( 'rocket_geotargetingwp_enabled_cookies', [ 'country' ] );
foreach ( $enabled_cookies as $enabled_cookie ) {
if ( ! in_array( 'geot_rocket_' . $enabled_cookie, $cookies, true ) ) {
$cookies[] = 'geot_rocket_' . $enabled_cookie;
}
}
return $cookies;
}
}
@@ -0,0 +1,50 @@
<?php
namespace WP_Rocket\ThirdParty;
trait ReturnTypesTrait {
/**
* Returns false.
*
* @since 3.6.1
*
* @return bool
*/
public function return_false() {
return false;
}
/**
* Returns true.
*
* @since 3.6.1
*
* @return true
*/
public function return_true() {
return true;
}
/**
* Returns an empty string.
*
* @since 3.6.1
*
* @return string Empty string
*/
public function return_empty_string() {
return '';
}
/**
* Returns an empty array.
*
* @since 3.6.1
*
* @return array Empty array.
*/
public function return_empty_array() {
return [];
}
}
@@ -0,0 +1,261 @@
<?php
namespace WP_Rocket\ThirdParty;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Subscriber\Third_Party\Plugins\Images\Webp\EWWW_Subscriber;
use WP_Rocket\Subscriber\Third_Party\Plugins\Images\Webp\Imagify_Subscriber;
use WP_Rocket\Subscriber\Third_Party\Plugins\Images\Webp\Optimus_Subscriber;
use WP_Rocket\Subscriber\Third_Party\Plugins\Images\Webp\ShortPixel_Subscriber;
use WP_Rocket\Subscriber\Third_Party\Plugins\Mobile_Subscriber;
use WP_Rocket\Subscriber\Third_Party\Plugins\NGG_Subscriber;
use WP_Rocket\Subscriber\Third_Party\Plugins\SyntaxHighlighter_Subscriber;
use WP_Rocket\ThirdParty\Plugins\Ads\Adthrive;
use WP_Rocket\ThirdParty\Plugins\ConvertPlug;
use WP_Rocket\ThirdParty\Plugins\Ecommerce\BigCommerce;
use WP_Rocket\ThirdParty\Plugins\Ecommerce\WooCommerceSubscriber;
use WP_Rocket\ThirdParty\Plugins\I18n\TranslatePress;
use WP_Rocket\ThirdParty\Plugins\I18n\WPML;
use WP_Rocket\ThirdParty\Plugins\InlineRelatedPosts;
use WP_Rocket\ThirdParty\Plugins\ModPagespeed;
use WP_Rocket\ThirdParty\Plugins\Optimization\AMP;
use WP_Rocket\ThirdParty\Plugins\Optimization\Autoptimize;
use WP_Rocket\ThirdParty\Plugins\Optimization\Ezoic;
use WP_Rocket\ThirdParty\Plugins\Optimization\WPMeteor;
use WP_Rocket\ThirdParty\Plugins\PageBuilder\BeaverBuilder;
use WP_Rocket\ThirdParty\Plugins\PageBuilder\Elementor;
use WP_Rocket\ThirdParty\Plugins\PDFEmbedder;
use WP_Rocket\ThirdParty\Plugins\PWA;
use WP_Rocket\ThirdParty\Plugins\RevolutionSlider;
use WP_Rocket\ThirdParty\Plugins\Security\WordFenceCompatibility;
use WP_Rocket\ThirdParty\Plugins\SEO\Yoast;
use WP_Rocket\ThirdParty\Plugins\SimpleCustomCss;
use WP_Rocket\ThirdParty\Plugins\Smush;
use WP_Rocket\ThirdParty\Plugins\TheEventsCalendar;
use WP_Rocket\ThirdParty\Plugins\ThirstyAffiliates;
use WP_Rocket\ThirdParty\Plugins\UnlimitedElements;
use WP_Rocket\ThirdParty\Plugins\CDN\{Cloudflare, CloudflareFacade};
use WP_Rocket\ThirdParty\Plugins\Jetpack;
use WP_Rocket\ThirdParty\Plugins\WPGeotargeting;
use WP_Rocket\ThirdParty\Plugins\SEO\RankMathSEO;
use WP_Rocket\ThirdParty\Plugins\SEO\AllInOneSEOPack;
use WP_Rocket\ThirdParty\Plugins\SEO\SEOPress;
use WP_Rocket\ThirdParty\Plugins\SEO\TheSEOFramework;
use WP_Rocket\ThirdParty\Plugins\Optimization\RocketLazyLoad;
use WP_Rocket\ThirdParty\Plugins\Optimization\Perfmatters;
use WP_Rocket\ThirdParty\Plugins\Optimization\RapidLoad;
/**
* Service provider for WP Rocket third party compatibility
*
* @since 3.3
*/
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 = [
'mobile_subscriber',
'woocommerce_subscriber',
'syntaxhighlighter_subscriber',
'elementor_subscriber',
'ngg_subscriber',
'smush_subscriber',
'imagify_webp_subscriber',
'shortpixel_webp_subscriber',
'ewww_webp_subscriber',
'optimus_webp_subscriber',
'bigcommerce_subscriber',
'beaverbuilder_subscriber',
'amp_subscriber',
'simple_custom_css',
'pdfembedder',
'mod_pagespeed',
'adthrive',
'autoptimize',
'wp-meteor',
'revolution_slider_subscriber',
'wordfence_subscriber',
'ezoic',
'pwa',
'convertplug',
'unlimited_elements',
'inline_related_posts',
'jetpack',
'rank_math_seo',
'all_in_one_seo_pack',
'seopress',
'the_seo_framework',
'wpml',
'cloudflare_plugin_facade',
'cloudflare_plugin_subscriber',
'rocket_lazy_load',
'the_events_calendar',
'perfmatters',
'rapidload',
'translatepress',
'wpgeotargeting',
];
/**
* Registers the subscribers in the container
*
* @since 3.3
*
* @return void
*/
public function register() {
$options = $this->getContainer()->get( 'options' );
$this->getContainer()
->share( 'mobile_subscriber', Mobile_Subscriber::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'elementor_subscriber', Elementor::class )
->addArgument( $options )
->addArgument( rocket_direct_filesystem() )
->addArgument( $this->getContainer()->get( 'delay_js_html' ) )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'woocommerce_subscriber', WooCommerceSubscriber::class )
->addArgument( $this->getContainer()->get( 'delay_js_html' ) )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'syntaxhighlighter_subscriber', SyntaxHighlighter_Subscriber::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'ngg_subscriber', NGG_Subscriber::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'smush_subscriber', Smush::class )
->addArgument( $this->getContainer()->get( 'options_api' ) )
->addArgument( $this->getContainer()->get( 'options' ) )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'imagify_webp_subscriber', Imagify_Subscriber::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'shortpixel_webp_subscriber', ShortPixel_Subscriber::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'ewww_webp_subscriber', EWWW_Subscriber::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'optimus_webp_subscriber', Optimus_Subscriber::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'bigcommerce_subscriber', BigCommerce::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'beaverbuilder_subscriber', BeaverBuilder::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'amp_subscriber', AMP::class )
->addArgument( $options )->addArgument( $this->getContainer()->get( 'cdn_subscriber' ) )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'simple_custom_css', SimpleCustomCss::class )
->addArgument( WP_ROCKET_CACHE_BUSTING_PATH )->addArgument( WP_ROCKET_CACHE_BUSTING_URL )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'pdfembedder', PDFEmbedder::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'mod_pagespeed', ModPagespeed::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'adthrive', Adthrive::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'autoptimize', Autoptimize::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'wp-meteor', WPMeteor::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'revolution_slider_subscriber', RevolutionSlider::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'wordfence_subscriber', WordFenceCompatibility::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'ezoic', Ezoic::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'thirstyaffiliates', ThirstyAffiliates::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'pwa', PWA::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'yoast_seo', Yoast::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'convertplug', ConvertPlug::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'unlimited_elements', UnlimitedElements::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'inline_related_posts', InlineRelatedPosts::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'wpml', WPML::class )
->addTag( 'common_subscriber' );
$this->getContainer()->add( 'cloudflare_plugin_facade', CloudflareFacade::class );
$this->getContainer()
->share( 'cloudflare_plugin_subscriber', Cloudflare::class )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'options_api' ) )
->addArgument( $this->getContainer()->get( 'beacon' ) )
->addArgument( $this->getContainer()->get( 'cloudflare_plugin_facade' ) )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'jetpack', Jetpack::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'convertplug', ConvertPlug::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'rank_math_seo', RankMathSEO::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'all_in_one_seo_pack', AllInOneSEOPack::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'seopress', SEOPress::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'the_seo_framework', TheSEOFramework::class )
->addArgument( $options )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'rocket_lazy_load', RocketLazyLoad::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'the_events_calendar', TheEventsCalendar::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'perfmatters', Perfmatters::class )
->addTag( 'common_subscriber' );
$this->getContainer()
->share( 'rapidload', RapidLoad::class );
$this->getContainer()->share( 'translatepress', TranslatePress::class );
$this->getContainer()->share( 'wpgeotargeting', WPGeotargeting::class );
}
}
@@ -0,0 +1,22 @@
<?php
namespace WP_Rocket\ThirdParty;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Interface for Subscriber Factories
*
* @since 3.6.3
*/
interface SubscriberFactoryInterface {
/**
* Get a Subscriber Interface object.
*
* @since 3.6.3
*
* @return Subscriber_Interface
*/
public function get_subscriber();
}
@@ -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;
}
}