add wp-rocket

This commit is contained in:
nguyen dung
2022-02-18 19:09:35 +07:00
parent 39b8cb3612
commit 3110d00ee7
927 changed files with 271703 additions and 2 deletions

View File

@@ -0,0 +1,89 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'FlywheelNginxCompat' ) ) {
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/flywheel.php';
}
if ( defined( 'DB_HOST' ) && strpos( DB_HOST, '.wpserveur.net' ) !== false ) {
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/wp-serveur.php';
}
if ( rocket_is_plugin_active( 'sg-cachepress/sg-cachepress.php' ) ) {
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/siteground.php';
}
if ( class_exists( 'WPaaS\Plugin' ) ) {
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/godaddy.php';
}
if ( isset( $_SERVER['KINSTA_CACHE_ZONE'] ) ) {
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/kinsta.php';
}
if ( defined( 'PL_INSTANCE_REF' ) && class_exists( '\Presslabs\Cache\CacheHandler' ) && file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) {
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/presslabs.php';
}
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/pagely.php';
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/nginx.php';
require WP_ROCKET_3RD_PARTY_PATH . 'hosting/pressidium.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/geotargetingwp.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/slider/layerslider.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/slider/meta-slider.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/slider/soliloquy.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/i18n/wpml.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/i18n/polylang.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/aelia-currencyswitcher.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/aelia-prices-by-country.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/aelia-tax-display-by-country.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/woocommerce-multilingual.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/woocommerce-currency-converter-widget.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/edd-software-licencing.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/easy-digital-downloads.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/ithemes-exchange.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/jigoshop.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/wpshop.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/ecommerce/give.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/age-verify.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/autoptimize.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/envira-gallery.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/cookies/cookie-notice.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/cookies/uk-cookie-consent.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/cookies/eu-cookie-law.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/cookies/weepie-cookie-allow.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/cookies/gdpr.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/rating/kk-star-ratings.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/rating/wp-postratings.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/wp-print.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/buddypress.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/disqus.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/custom-login.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/mobile/wp-appkit.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/seo/seopress.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/seo/rank-math-seo.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/seo/yoast-seo.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/seo/the-seo-framework.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/seo/all-in-one-seo-pack.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/seo/premium-seo-pack.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/wp-rest-api.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/page-builder/thrive-visual-editor.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/page-builder/visual-composer.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/security/secupress.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/security/sf-move-login.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/security/wps-hide-login.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/varnish-http-purge.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/thrive-leads.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/mailchimp.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/advanced-custom-fields.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/wp-offload-s3.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/wp-offload-s3-assets.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/s2member.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/sumome.php';
require WP_ROCKET_3RD_PARTY_PATH . 'plugins/nginx-helper.php';
require WP_ROCKET_3RD_PARTY_PATH . 'themes/avada.php';
require WP_ROCKET_3RD_PARTY_PATH . 'themes/studiopress.php';
require WP_ROCKET_3RD_PARTY_PATH . 'themes/uncode.php';

View File

@@ -0,0 +1,80 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* 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.
*/
function rocket_flywheel_varnish_field( $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' ),
'Flywheel'
);
return $settings;
}
add_filter( 'rocket_varnish_field_settings', 'rocket_flywheel_varnish_field' );
add_filter( 'rocket_display_input_varnish_auto_purge', '__return_false' );
/**
* Allow to purge Varnish on Flywheel websites
*
* @since 2.6.8
*/
add_filter( 'do_rocket_varnish_http_purge', '__return_true' );
add_filter( 'do_rocket_generate_caching_files', '__return_false' );
// Prevent mandatory cookies on hosting with server cache.
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array', PHP_INT_MAX );
/**
* Set up the right Varnish IP for Flywheel
*
* @since 2.6.8
* @param array $varnish_ip Varnish IP.
*/
function rocket_varnish_ip_on_flywheel( $varnish_ip ) {
$varnish_ip[] = '127.0.0.1';
return $varnish_ip;
}
add_filter( 'rocket_varnish_ip', 'rocket_varnish_ip_on_flywheel' );
/**
* Remove WP Rocket functions on WP core action hooks to prevent triggering a double cache clear.
*
* @since 3.3.1
* @author Remy Perona
*
* @return void
*/
function rocket_flywheel_remove_partial_purge_hooks() {
// WP core action hooks rocket_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' );
}
add_action( 'wp_rocket_loaded', 'rocket_flywheel_remove_partial_purge_hooks' );

View File

@@ -0,0 +1,130 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* 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.
*/
function rocket_godaddy_varnish_field( $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' ),
'GoDaddy'
);
return $settings;
}
add_filter( 'rocket_varnish_field_settings', 'rocket_godaddy_varnish_field' );
add_filter( 'rocket_display_input_varnish_auto_purge', '__return_false' );
add_filter( 'set_rocket_wp_cache_define', '__return_true' );
// Prevent mandatory cookies on hosting with server cache.
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array', PHP_INT_MAX );
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false' );
/**
* Remove expiration on HTML to prevent issue with Varnish cache.
*
* @since 2.9.5
* @author Remy Perona
*
* @param string $rules htaccess rules.
* @return string Updated htaccess rules.
*/
function rocket_remove_html_expire_goddady( $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;
}
add_filter( 'rocket_htaccess_mod_expires', 'rocket_remove_html_expire_goddady', 5 );
/**
* Call the Varnish server to purge the cache with GoDaddy.
*
* @since 2.9.5
*
* @return void
*/
function rocket_clean_domain_godaddy() {
rocket_godaddy_request( 'BAN' );
}
add_action( 'before_rocket_clean_domain', 'rocket_clean_domain_godaddy' );
/**
* Call the Varnish server to purge a specific URL with GoDaddy.
*
* @since 2.9.5
*
* @param string $url URL to purge.
* @return void
*/
function rocket_clean_file_godaddy( $url ) {
rocket_godaddy_request( 'PURGE', home_url( $url ) );
}
add_action( 'before_rocket_clean_file', 'rocket_clean_file_godaddy' );
/**
* Call the Varnish server to purge the home with GoDaddy.
*
* @since 2.9.5
*
* @param string $root root URL.
* @param string $lang language code.
* @return void
*/
function rocket_clean_home_godaddy( $root, $lang ) {
$home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
$home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base );
rocket_godaddy_request( 'PURGE', $home_url );
rocket_godaddy_request( 'PURGE', $home_pagination_url );
}
add_action( 'before_rocket_clean_home', 'rocket_clean_home_godaddy', 10, 2 );
/**
* Perform the call to the Varnish server to purge
*
* @since 2.9.5
* @source WPaaS\Cache
*
* @param string $method can be BAN or PURGE.
* @param string $url URL to purge.
* @return void
*/
function rocket_godaddy_request( $method, $url = null ) {
if ( ! method_exists( 'WPass\Plugin', 'vip' ) ) {
return;
}
if ( empty( $url ) ) {
$url = home_url();
}
$host = rocket_extract_url_component( $url, PHP_URL_HOST );
$url = set_url_scheme( str_replace( $host, WPaas\Plugin::vip(), $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,
],
]
);
}

View File

@@ -0,0 +1,166 @@
<?php
defined( 'ABSPATH' ) || exit;
add_filter( 'do_rocket_generate_caching_files', '__return_false', PHP_INT_MAX );
add_filter( 'rocket_display_varnish_options_tab', '__return_false' );
// Prevent mandatory cookies on hosting with server cache.
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array', PHP_INT_MAX );
global $kinsta_cache;
if ( isset( $kinsta_cache ) && class_exists( '\\Kinsta\\CDN_Enabler' ) ) {
/**
* Clear Kinsta cache when clearing WP Rocket cache
*
* @since 3.0
* @author Remy Perona
*
* @return void
*/
function rocket_clean_kinsta_cache() {
global $kinsta_cache;
if ( ! empty( $kinsta_cache->kinsta_cache_purge ) ) {
$kinsta_cache->kinsta_cache_purge->purge_complete_caches();
}
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_kinsta_cache' );
/**
* Partially clear Kinsta cache when partially clearing WP Rocket cache
*
* @since 3.0
* @author Remy Perona
*
* @param object $post Post object.
* @return void
*/
function rocket_clean_kinsta_post_cache( $post ) {
global $kinsta_cache;
$kinsta_cache->kinsta_cache_purge->initiate_purge( $post->ID, 'post' );
}
add_action( 'after_rocket_clean_post', 'rocket_clean_kinsta_post_cache' );
/**
* Clears Kinsta cache for the homepage URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.0.4
* @author Remy Perona
*
* @param string $root WP Rocket root cache path.
* @param string $lang Current language.
* @return void
*/
function rocket_clean_kinsta_cache_home( $root = '', $lang = '' ) {
$url = get_rocket_i18n_home_url( $lang );
$url = trailingslashit( $url ) . 'kinsta-clear-cache/';
wp_remote_get(
$url,
[
'blocking' => false,
'timeout' => 0.01,
]
);
}
add_action( 'after_rocket_clean_home', 'rocket_clean_kinsta_cache_home', 10, 2 );
/**
* Clears Kinsta cache for a specific URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.0.4
* @author Remy Perona
*
* @param string $url URL to purge.
* @return void
*/
function rocket_clean_kinsta_cache_url( $url ) {
$url = trailingslashit( $url ) . 'kinsta-clear-cache/';
wp_remote_get(
$url,
[
'blocking' => false,
'timeout' => 0.01,
]
);
}
add_action( 'after_rocket_clean_file', 'rocket_clean_kinsta_cache_url' );
/**
* Remove WP Rocket functions on WP core action hooks to prevent triggering a double cache clear.
*
* @since 3.0
* @author Remy Perona
*
* @return void
*/
function rocket_remove_partial_purge_hooks() {
// WP core action hooks rocket_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' );
}
add_action( 'wp_rocket_loaded', 'rocket_remove_partial_purge_hooks' );
if ( \Kinsta\CDN_Enabler::cdn_is_enabled() ) {
/**
* Add Kinsta CDN to WP Rocket CDN hosts list if enabled
*
* @since 3.0
* @author Remy Perona
*
* @param Array $hosts Array of CDN hosts.
* @return Array Updated array of CDN hosts
*/
function rocket_add_kinsta_cdn_cname( $hosts ) {
if ( ! isset( $_SERVER['KINSTA_CDN_DOMAIN'] ) ) {
return $hosts;
}
$hosts[] = sanitize_text_field( wp_unslash( $_SERVER['KINSTA_CDN_DOMAIN'] ) );
return $hosts;
}
add_filter( 'rocket_cdn_cnames', 'rocket_add_kinsta_cdn_cname', 1 );
}
} else {
add_action(
'admin_notices',
function() {
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 and CDN, 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>' ),
]
);
}
);
}

View File

@@ -0,0 +1,24 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with an usual NGINX configuration which include:
* try_files $uri $uri/ /index.php?q=$uri&$args
*
* @since 2.3.9
*
* @param array $query_strings Array of query strings to cache.
*
* @return array Updated array of query strings.
*/
function rocket_better_nginx_compatibility( $query_strings ) {
global $is_nginx;
if ( $is_nginx ) {
$query_strings[] = 'q';
}
return $query_strings;
}
add_filter( 'rocket_cache_query_strings', 'rocket_better_nginx_compatibility' );

View File

@@ -0,0 +1,31 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Clear WP Rocket cache after purged the Varnish cache via Pagely hosting.
*
* @since 2.5.7
*
* @return void
*/
function rocket_clear_cache_after_pagely() {
// Clear all caching files.
rocket_clean_domain();
}
add_action( 'pagely_cache_purge_after', 'rocket_clear_cache_after_pagely' );
/**
* Call the cache server to purge the cache with Pagely hosting.
*
* @since 2.5.7
*
* @return void
*/
function rocket_clean_pagely() {
if ( class_exists( 'PagelyCachePurge' ) ) {
$purger = new PagelyCachePurge();
$purger->purgeAll();
}
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_pagely' );

View File

@@ -0,0 +1,61 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'WP_NINUKIS_WP_NAME' ) ) {
/**
* 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.
*/
function rocket_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;
}
add_filter( 'rocket_varnish_field_settings', 'rocket_pressidium_varnish_field' );
add_filter( 'rocket_display_input_varnish_auto_purge', '__return_false' );
// Prevent mandatory cookies on hosting with server cache.
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array', PHP_INT_MAX );
/**
* Clear WP Rocket cache after purged the Varnish cache via Pressidium Hosting
*
* @since 2.5.11
*
* @return void
*/
function rocket_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();
// Preload cache.
run_rocket_bot();
run_rocket_sitemap_preload();
}
}
add_action( 'admin_init', 'rocket_clear_cache_after_pressidium' );
}
if ( class_exists( 'Ninukis_Plugin' ) ) {
/**
* Call the cache server to purge the cache with Pressidium hosting.
*
* @since 2.6
*
* @return void
*/
function rocket_clean_pressidium() {
$plugin = Ninukis_Plugin::get_instance();
$plugin->purgeAllCaches();
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_pressidium' );
}

View File

@@ -0,0 +1,98 @@
<?php
defined( 'ABSPATH' ) || exit;
require_once WP_CONTENT_DIR . '/advanced-cache.php';
add_action( 'pl_pre_cache_refresh', 'rocket_clean_files', 0 );
add_filter( 'rocket_display_varnish_options_tab', '__return_false' );
add_filter( 'do_rocket_generate_caching_files', '__return_false', PHP_INT_MAX );
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array', PHP_INT_MAX );
add_action( 'after_rocket_clean_home', 'rocket_pl_clean_home', 10, 2 );
add_action( 'after_rocket_clean_file', 'rocket_pl_clean_post', 2 );
add_action( 'pl_pre_url_button_cache_refresh', 'rocket_clean_files' );
add_action( 'wp_rocket_loaded', 'rocket_remove_partial_purge_hooks' );
/**
* We clear the cache only on the post, homepage and listings when creating/updating/deleting posts.
*
* @since 3.3
*
* @param object $post The Post object itself for which the action occured.
* @param array $permalink A list of permalinks to be flushed from cache.
*
* @return void
*/
function rocket_pl_clean_post( $post = false, $permalink = false ) {
if ( ! $post || ! $permalink ) {
return;
}
$cache_handler = new \Presslabs\Cache\CacheHandler();
$cache_handler->invalidate_url( $permalink[0], true );
$cache_handler->invalidate_url( home_url( '/' ), true );
$cache_handler->purge_cache( 'listing' );
}
/**
* We clear the cache for the homepage URL when using "Purge this URL" from the admin bar on the front end.
*
* @since 3.3
*
* @param string $root WP Rocket root cache path.
* @param string $lang Current language.
*
* @return void
*/
function rocket_pl_clean_home( $root = false, $lang = false ) {
if ( ! $post || ! $permalink ) {
return;
}
$cache_handler = new \Presslabs\Cache\CacheHandler();
$cache_handler->invalidate_url( home_url( '/' ), true );
}
/**
* Remove WP Rocket functions on WP core action hooks to prevent triggering a double cache clear.
*
* @since 3.3
*
* @return void
*/
function rocket_remove_partial_purge_hooks() {
// WP core action hooks rocket_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' );
}
if ( ! defined( 'DISABLE_CDN_OFFLOAD' ) && defined( 'PL_CDN_HOST' ) ) {
/**
* If we have CDN enabled we'll add our HOST to the list.
*
* @since 3.3
*
* @param array $hosts Array of CDN hosts.
*
* @return array Updated array of CDN hosts
*/
function rocket_add_pl_cdn( $hosts ) {
$hosts[] = constant( 'PL_CDN_HOST' );
return $hosts;
}
add_filter( 'rocket_cdn_cnames', 'rocket_add_pl_cdn', 1 );
}

View File

@@ -0,0 +1,87 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Returns the current version of the SG Optimizer plugin.
*
* @since 3.2.3.1
* @author Remy Perona
*
* @return string version number.
*/
function rocket_get_sg_optimizer_version() {
static $version;
if ( isset( $version ) ) {
return $version;
}
$sg_optimizer = get_file_data( WP_PLUGIN_DIR . '/sg-cachepress/sg-cachepress.php', [ 'Version' => 'Version' ] );
$version = $sg_optimizer['Version'];
return $version;
}
/**
* Checks if SG Optimizer Supercache is active.
*
* @since 3.2.3.1
* @author Remy Perona
*
* @return bool
*/
function rocket_is_supercacher_active() {
if ( ! version_compare( rocket_get_sg_optimizer_version(), '5.0' ) < 0 ) {
global $sg_cachepress_environment;
return isset( $sg_cachepress_environment ) && $sg_cachepress_environment instanceof SG_CachePress_Environment && $sg_cachepress_environment->cache_is_enabled();
}
return (bool) get_option( 'siteground_optimizer_enable_cache', 0 );
}
/**
* Call the cache server to purge the cache with SuperCacher (SiteGround).
*
* @since 2.3
*
* @return void
*/
function rocket_clean_supercacher() {
if ( ! rocket_is_supercacher_active() ) {
return;
}
if ( ! version_compare( rocket_get_sg_optimizer_version(), '5.0' ) < 0 ) {
SiteGround_Optimizer\Supercacher\Supercacher::purge_cache();
} elseif ( isset( $sg_cachepress_supercacher ) && $sg_cachepress_supercacher instanceof SG_CachePress_Supercacher ) {
$sg_cachepress_supercacher->purge_cache();
}
}
if ( rocket_is_supercacher_active() ) {
add_action( 'admin_post_sg-cachepress-purge', 'rocket_clean_domain', 0 );
add_action( 'after_rocket_clean_domain', 'rocket_clean_supercacher' );
add_filter( 'rocket_display_varnish_options_tab', '__return_false' );
// Prevent mandatory cookies on hosting with server cache.
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array', PHP_INT_MAX );
/**
* Force WP Rocket caching on SG Optimizer versions before 4.0.5.
*
* @since 3.0.4
* @author Arun Basil Lal
*
* @link https://github.com/wp-media/wp-rocket/issues/925
*/
if ( version_compare( rocket_get_sg_optimizer_version(), '4.0.5' ) < 0 ) {
add_filter( 'do_rocket_generate_caching_files', '__return_true', 11 );
}
if ( version_compare( rocket_get_sg_optimizer_version(), '5.0' ) < 0 ) {
add_action( 'wp_ajax_sg-cachepress-purge', 'rocket_clean_domain', 0 );
} else {
add_action( 'wp_ajax_admin_bar_purge_cache', 'rocket_clean_domain', 0 );
}
}

View File

@@ -0,0 +1,35 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Allow to purge Varnish on WP Serveur websites.
*
* @since 2.6.11
*/
add_filter( 'do_rocket_varnish_http_purge', '__return_true' );
// Prevent mandatory cookies on hosting with server cache.
add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array', PHP_INT_MAX );
/**
* 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.
*/
function rocket_wpserveur_varnish_field( $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 Serveur'
);
return $settings;
}
add_filter( 'rocket_varnish_field_settings', 'rocket_wpserveur_varnish_field' );
add_filter( 'rocket_display_input_varnish_auto_purge', '__return_false' );

View File

@@ -0,0 +1,18 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Clear cache when ACF options page is updated.
*
* @since 2.10.7
* @author Remy Perona
*
* @param string $post_id ACF options page ID is 'options'.
*/
function rocket_clear_cache_on_acf_options_save( $post_id ) {
if ( 'options' === $post_id ) {
rocket_clean_domain();
}
}
add_action( 'acf/save_post', 'rocket_clear_cache_on_acf_options_save' );

View File

@@ -0,0 +1,59 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Conflict with Age Verify: don't cache pages until the age-verified cookie is set
*
* @since 2.7
*/
if ( class_exists( 'Age_Verify' ) && defined( 'Age_Verify::SLUG' ) ) :
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 18 );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_cache_mandatory_cookie_for_age_verify' );
endif;
/**
* Add age-verified to the list of mandatory cookies
*
* @since 2.7
*
* @param Array $cookies Array of mandatory cookies.
* @return Array Updated array of mandatory cookies
*/
function rocket_add_cache_mandatory_cookie_for_age_verify( $cookies ) {
$cookies[] = 'age-verified';
return $cookies;
}
/**
* Add age-verified cookie when we activate the plugin
*
* @since 2.7
*/
function rocket_activate_age_verify() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 18 );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_cache_mandatory_cookie_for_age_verify' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_age-verify/age-verify.php', 'rocket_activate_age_verify', 11 );
/**
* Remove age-verified cookie when we deactivate the plugin
*
* @since 2.7
*/
function rocket_deactivate_age_verify() {
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_cache_mandatory_cookie_for_age_verify' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_age-verify/age-verify.php', 'rocket_deactivate_age_verify', 11 );

View File

@@ -0,0 +1,175 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'autoptimizeCache' ) ) :
/**
* Improvement with Autoptimize: clear the cache when Autoptimize's cache is cleared
*
* @since 2.7
*/
add_action( 'autoptimize_action_cachepurged', 'rocket_clean_domain' );
endif;
if ( class_exists( 'autoptimizeConfig' ) ) :
/**
* Deactivate WP Rocket lazyload if Autoptimize lazyload is enabled
*
* @since 3.3.4
* @author Remy Perona
*
* @param string $old_value Previous autoptimize option value.
* @param string $value New autoptimize option value.
* @return void
*/
function rocket_maybe_deactivate_lazyload( $old_value, $value ) {
if ( empty( $old_value['autoptimize_imgopt_checkbox_field_3'] ) && ! empty( $value['autoptimize_imgopt_checkbox_field_3'] ) ) {
update_rocket_option( 'lazyload', 0 );
update_rocket_option( 'lazyload_iframes', 0 );
update_rocket_option( 'lazyload_youtube', 0 );
}
}
add_action( 'update_option_autoptimize_imgopt_settings', 'rocket_maybe_deactivate_lazyload', 10, 2 );
/**
* Deactivate WP Rocket CSS Minification if Autoptimize CSS minification is enabled
*
* @since 2.9.5
* @author Remy Perona
*
* @param string $old_value Previous autoptimize option value.
* @param string $value New autoptimize option value.
*/
function rocket_maybe_deactivate_minify_css( $old_value, $value ) {
if ( $value !== $old_value && 'on' === $value ) {
update_rocket_option( 'minify_css', 0 );
update_rocket_option( 'minify_concatenate_css', 0 );
}
}
add_action( 'update_option_autoptimize_css', 'rocket_maybe_deactivate_minify_css', 10, 2 );
/**
* Deactivate WP Rocket JS Minification if Autoptimize JS minification is enabled
*
* @since 2.9.5
* @author Remy Perona
*
* @param string $old_value Previous autoptimize option value.
* @param string $value New autoptimize option value.
*/
function rocket_maybe_deactivate_minify_js( $old_value, $value ) {
if ( $value !== $old_value && 'on' === $value ) {
update_rocket_option( 'minify_js', 0 );
update_rocket_option( 'minify_concatenate_js', 0 );
}
}
add_action( 'update_option_autoptimize_js', 'rocket_maybe_deactivate_minify_js', 10, 2 );
/**
* Deactivate WP Rocket async CSS if Autoptimize async CSS is enabled
*
* @since 2.10
* @author Remy Perona
*
* @param string $old_value Previous autoptimize option value.
* @param string $value New autoptimize option value.
*/
function rocket_maybe_deactivate_css_defer( $old_value, $value ) {
if ( $value !== $old_value && 'on' === $value ) {
update_rocket_option( 'autoptimize_css_defer', 0 );
}
}
add_action( 'update_option_autoptimize_css_defer', 'rocket_maybe_deactivate_css_defer', 10, 2 );
endif;
/**
* Disable WP Rocket minification options when activating Autoptimize and values are already in the database.
*
* @since 2.9.5
* @author Remy Perona
*/
function rocket_activate_autoptimize() {
if ( 'on' === get_option( 'autoptimize_css' ) ) {
update_rocket_option( 'minify_css', 0 );
update_rocket_option( 'minify_concatenate_css', 0 );
}
if ( 'on' === get_option( 'autoptimize_js' ) ) {
update_rocket_option( 'minify_js', 0 );
update_rocket_option( 'minify_concatenate_js', 0 );
}
if ( 'on' === get_option( 'autoptimize_css_defer' ) ) {
update_rocket_option( 'async_css', 0 );
}
$lazyload = get_option( 'autoptimize_imgopt_settings' );
if ( ! empty( $lazyload['autoptimize_imgopt_checkbox_field_3'] ) ) {
update_rocket_option( 'lazyload', 0 );
update_rocket_option( 'lazyload_iframes', 0 );
update_rocket_option( 'lazyload_youtube', 0 );
}
}
add_action( 'activate_autoptimize/autoptimize.php', 'rocket_activate_autoptimize', 11 );
/**
* Disable WP Rocket lazyload fields if Autoptimize lazyload is enabled
*
* @since 3.3.4
* @author Remy Perona
*
* @return bool
*/
function rocket_maybe_disable_lazyload() {
$lazyload = get_option( 'autoptimize_imgopt_settings' );
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) && ! empty( $lazyload['autoptimize_imgopt_checkbox_field_3'] ) ) {
return true;
}
return false;
}
/**
* Disable WP Rocket CSS minification field if Autoptimize CSS minification is enabled
*
* @since 2.9.5
* @author Remy Perona
*
* @return bool|null True if it is active
*/
function rocket_maybe_disable_minify_css() {
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) && 'on' === get_option( 'autoptimize_css' ) ) {
return true;
}
}
/**
* Disable WP Rocket JS minification field if Autoptimize JS minification is enabled
*
* @since 2.9.5
* @author Remy Perona
*
* @return bool|null True if it is active
*/
function rocket_maybe_disable_minify_js() {
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) && 'on' === get_option( 'autoptimize_js' ) ) {
return true;
}
}
/**
* Disable WP Rocket async CSS field if Autoptimize async CSS is enabled
*
* @since 2.10
* @author Remy Perona
*
* @return bool|null True if it is active
*/
function rocket_maybe_disable_async_css() {
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) && 'on' === get_option( 'autoptimize_css_defer' ) ) {
return true;
}
}

View File

@@ -0,0 +1,47 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'BuddyPress' ) ) :
/**
* Conflict with BuddyPress: don't apply LazyLoad on BuddyPress profil pages & group creation
*
* @since 2.8.15 Improve checks for user profile & disable for cover images
* @since 2.6.9
*/
if ( function_exists( 'bp_is_user_profile' ) ) :
/**
* Prevent lazyload if on a BuddyPress profil page
*
* @param Bool $run_filter Do lazyload value.
* @return Bool False if on a BuddyPress profil page, initial value otherwise
*/
function rocket_deactivate_lazyload_on_buddypress_profil_pages( $run_filter ) {
if ( bp_is_user_profile() ) {
return false;
}
return $run_filter;
}
add_filter( 'do_rocket_lazyload', 'rocket_deactivate_lazyload_on_buddypress_profil_pages' );
add_filter( 'do_rocket_lazyload_iframes', 'rocket_deactivate_lazyload_on_buddypress_profil_pages' );
endif;
if ( function_exists( 'bp_is_group_creation_step' ) && function_exists( 'bp_is_group_admin_screen' ) ) :
/**
* Prevent lazyload if on a BuddyPress group creation page
*
* @param Bool $run_filter Do lazyload value.
* @return Bool False if on a BuddyPress profil page, initial value otherwise
*/
function rocket_deactivate_lazyload_on_buddypress_group_pages( $run_filter ) {
if ( bp_is_group_creation_step( 'group-avatar' ) || bp_is_group_creation_step( 'group-cover-image' ) || bp_is_group_admin_screen( 'group-avatar' ) || bp_is_group_admin_screen( 'group-cover-image' ) ) {
return false;
}
return $run_filter;
}
add_filter( 'do_rocket_lazyload', 'rocket_deactivate_lazyload_on_buddypress_group_pages' );
add_filter( 'do_rocket_lazyload_iframes', 'rocket_deactivate_lazyload_on_buddypress_group_pages' );
endif;
endif;

View File

@@ -0,0 +1,81 @@
<?php
/**
* Compatibility with Cookie Notice by dFactory.
*
* @since 2.11.6
* @author Arun Basil Lal
* @link https://wordpress.org/plugins/cookie-notice/
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'Cookie_Notice' ) ) {
// Don't add the WP Rocket rewrite rules to avoid issues.
if ( ! class_exists( 'CC4R_options' ) || ! CC4R_options::rewrite_enabled() ) {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 56 );
}
// Create cache version based on value set in cookie_notice_accepted cookie.
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_cookie_notice_cookie' );
}
/**
* Return the cookie name set by Cookie Notice plugin.
*
* @since 2.11.6
* @author Arun Basil Lal
*
* @param array $cookies List of dynamic cookies.
* @return array List of dynamic cookies with the Cookie Notice cookie appended.
*/
function rocket_get_cookie_notice_cookie( $cookies ) {
$cookies[] = 'cookie_notice_accepted';
return $cookies;
}
/**
* Add dynamic cookie and mandatory cookie when Cookie Notice plugin is activated.
*
* @since 2.11.6
* @author Arun Basil Lal
*/
function rocket_add_cookie_notice_dynamic_cookie() {
// Don't add the WP Rocket rewrite rules to avoid issues.
if ( ! class_exists( 'CC4R_options' ) || ! CC4R_options::rewrite_enabled() ) {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 56 );
}
// Create cache version based on value set in cookie_notice_accepted cookie.
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_cookie_notice_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
// Clear WP Rocket cache.
rocket_clean_domain();
}
add_action( 'activate_cookie-notice/cookie-notice.php', 'rocket_add_cookie_notice_dynamic_cookie', 11 );
/**
* Remove dynamic cookie when Cookie Notice plugin is deactivated.
*
* @since 2.11.6
* @author Arun Basil Lal
*/
function rocket_remove_cookie_notice_dynamic_cookie() {
if ( ! class_exists( 'CC4R_options' ) || ! CC4R_options::rewrite_enabled() ) {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 56 );
}
remove_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_cookie_notice_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
// Clear WP Rocket cache.
rocket_clean_domain();
}
add_action( 'deactivate_cookie-notice/cookie-notice.php', 'rocket_remove_cookie_notice_dynamic_cookie', 11 );

View File

@@ -0,0 +1,89 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with EU Cookie Law
* https://wordpress.org/plugins/eu-cookie-law/
*
* @since 2.7
*/
if ( function_exists( 'eucookie_start' ) ) :
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_eu_cookie_law_mandatory_cookie' );
/**
* Update .htaccess & config files when the "Activate" and "Autoblock" options are turned on
*
* @since 2.7
*
* @param Array $old_value Array of previous values.
* @param Array $value Array of submitted values.
*/
function rocket_after_update_eu_cookie_law_options( $old_value, $value ) {
if ( ( isset( $old_value['enabled'], $value['enabled'] ) && ( $old_value['enabled'] === $value['enabled'] ) ) && isset( $old_value['autoblock'], $value['autoblock'] ) && $old_value['autoblock'] === $value['autoblock'] ) {
return;
}
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Update the config file.
rocket_generate_config_file();
}
add_action( 'update_option_peadig_eucookie', 'rocket_after_update_eu_cookie_law_options', 10, 2 );
// Don't add the WP Rocket rewrite rules to avoid issues.
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 58 );
endif;
/**
* Add mandatory cookie when we activate the plugin
*
* @since 2.7
*/
function rocket_activate_eu_cookie_law() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 58 );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_eu_cookie_law_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_eu-cookie-law/eu-cookie-law.php', 'rocket_activate_eu_cookie_law', 11 );
/**
* Remove mandatory cookie when we deactivate the plugin
*
* @since 2.7
*/
function rocket_deactivate_eu_cookie_law() {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 58 );
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_eu_cookie_law_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_eu-cookie-law/eu-cookie-law.php', 'rocket_deactivate_eu_cookie_law', 11 );
/**
* Add the EU Cookie Law to the list of mandatory cookies before generating caching files.
*
* @since 2.7
*
* @param Array $cookies Array of mandatory cookies.
* @return Array Updated array of mandatory cookies
*/
function rocket_add_eu_cookie_law_mandatory_cookie( $cookies ) {
$options = get_option( 'peadig_eucookie' );
if ( ! empty( $options['enabled'] ) && ! empty( $options['autoblock'] ) ) {
$cookies['eu-cookie-law'] = 'euCookie';
}
return $cookies;
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* Compatibility with GDPR by Trew Knowledge
*
* @link https://github.com/trewknowledge/GDPR/
* @link https://wordpress.org/plugins/gdpr/
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'GDPR' ) ) {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 60 );
// Create cache version based on value set in gdpr[] cookies.
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_gdpr_dynamic_cookies' );
}
/**
* Return the cookie names set by GDPR plugin
*
* @since 3.1.4
* @author jorditarrida
*
* @param array $cookies array List of dynamic cookies.
* @return array List of dynamic cookies with the GDPR cookie appended
*/
function rocket_get_gdpr_mandatory_cookies( $cookies ) {
$cookies[] = 'allowed_cookies';
$cookies[] = 'consent_types';
return $cookies;
}
/**
* Return the cookie names set by GDPR plugin
*
* @since 3.1.4
* @author jorditarrida
*
* @param array $cookies array List of dynamic cookies.
* @return array List of dynamic cookies with the GDPR cookie appended
*/
function rocket_get_gdpr_dynamic_cookies( $cookies ) {
$cookies['gdpr'] = [
'allowed_cookies',
'consent_types',
];
return $cookies;
}
/**
* Add dynamic cookie when GDPR plugin is activated
*
* @since 3.1.4
* @author jorditarrida
*/
function rocket_add_gdpr_mandatory_cookies() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 60 );
// Create cache version based on value set in GDPR cookies.
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_gdpr_dynamic_cookies' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
// Clear WP Rocket cache.
rocket_clean_domain();
}
add_action( 'activate_gdpr/gdpr.php', 'rocket_add_gdpr_mandatory_cookies', 11 );
/**
* Remove dynamic cookie when GDPR plugin is deactivated.
*
* @since 3.1.4
* @author jorditarrida
*/
function rocket_remove_gdpr_mandatory_cookies() {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 60 );
// Delete the dynamic cookie filter.
remove_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_gdpr_dynamic_cookies' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
// Clear WP Rocket cache.
rocket_clean_domain();
}
add_action( 'deactivate_gdpr/gdpr.php', 'rocket_remove_gdpr_mandatory_cookies', 11 );

View File

@@ -0,0 +1,73 @@
<?php
/**
* Compatibility with UK Cookie Consent.
*
* @since 3.2
* @author TheZoker
* @link https://wordpress.org/plugins/uk-cookie-consent/
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'CTCC_Public' ) ) {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 62 );
// Create cache version based on value set in cookie_consent_accepted cookie.
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_cookie_uk_consent_cookie' );
}
/**
* Return the cookie name set by UK Cookie Consent plugin.
*
* @since 3.2
* @author TheZoker
*
* @param array $cookies List of dynamic cookies.
* @return array List of dynamic cookies with the UK Cookie Consent cookie appended.
*/
function rocket_get_cookie_uk_consent_cookie( $cookies ) {
$cookies[] = 'catAccCookies';
return $cookies;
}
/**
* Add dynamic cookie and mandatory cookie when UK Cookie Consent plugin is activated.
*
* @since 3.2
* @author TheZoker
*/
function rocket_add_uk_cookie_consent_dynamic_cookie() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 62 );
// Create cache version based on value set in cookie_consent_accepted cookie.
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_cookie_uk_consent_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
// Clear WP Rocket cache.
rocket_clean_domain();
}
add_action( 'activate_uk-cookie-consent/uk-cookie-consent.php', 'rocket_add_uk_cookie_consent_dynamic_cookie', 11 );
/**
* Remove dynamic cookie when Cookie Consent plugin is deactivated.
*
* @since 3.2
* @author TheZoker
*/
function rocket_remove_uk_cookie_consent_dynamic_cookie() {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 62 );
remove_filter( 'rocket_cache_dynamic_cookies', 'rocket_get_cookie_uk_consent_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
// Clear WP Rocket cache.
rocket_clean_domain();
}
add_action( 'deactivate_uk-cookie-consent/uk-cookie-consent.php', 'rocket_remove_uk_cookie_consent_dynamic_cookie', 11 );

View File

@@ -0,0 +1,53 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with WeePie Cookie Allow
*
* @since 2.9
*/
if ( class_exists( 'WpieCookieAllow' ) ) :
add_action( 'update_option_wpca_settings_general', 'rocket_after_update_wp_cookie_allow_options', 10, 2 );
add_action( 'update_option_wpca_settings_style', 'rocket_after_update_wp_cookie_allow_options', 10, 2 );
add_action( 'update_option_wpca_settings_content', 'rocket_after_update_wp_cookie_allow_options', 10, 2 );
add_action( 'update_option_wpca_settings_consent_log', 'rocket_after_update_wp_cookie_allow_options', 10, 2 );
endif;
/**
* Update .htaccess & config files when the "Enabled" and "Autoblock" options are turned on.
*
* @since 2.9
* @author Remy Perona
*
* @param array $old_value Previous values for the plugin options.
* @param array $value New values for the plugin options.
*/
function rocket_after_update_wp_cookie_allow_options( $old_value, $value ) {
// clear the cache because WeePie Cookie Allow plugin settings might have been changed.
rocket_clean_domain();
}
/**
* Add cookies when we activate the plugin.
*
* @since 2.9
* @author Remy Perona
*/
function rocket_activate_wp_cookie_allow() {
// clear the cache because plugin might be enabled already before.
rocket_clean_domain();
}
add_action( 'activate_wp-cookie-allow/wp-cookie-allow.php', 'rocket_activate_wp_cookie_allow', 11 );
/**
* Remove cookies when we deactivate the plugin
*
* @since 2.9
* @author Remy Perona
*/
function rocket_deactivate_wp_cookie_allow() {
// clear the cache because the bar/box and other WeePie Cookie Allow plugin frontend HTML is not needed anymore.
rocket_clean_domain();
}
add_action( 'deactivate_wp-cookie-allow/wp-cookie-allow.php', 'rocket_deactivate_wp_cookie_allow', 11 );

View File

@@ -0,0 +1,63 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Exclude plugin custom login page template from cache.
*
* @since 2.7
*/
if ( class_exists( 'Custom_Login_Page_Template' ) ) {
add_filter( 'rocket_cache_reject_uri', 'rocket_add_custom_login_exclude_pages' );
add_action( 'update_option_custom_login_page_template', 'rocket_after_update_single_options', 10, 2 );
}
/**
* Add custom login page to excluded urls array
*
* @since 2.7
* @author Remy Perona
*
* @param Array $urls Array of pages to exclude.
* @return Array Updated array of pages to exclude
*/
function rocket_add_custom_login_exclude_pages( $urls ) {
$clpt_options = get_option( 'custom_login_page_template' );
$urls = array_merge( $urls, get_rocket_i18n_translated_post_urls( $clpt_options['login_page_id'], 'page' ) );
return $urls;
}
/**
* Add custom login page to excluded urls array on plugin activation
*
* @since 2.7
* @author Remy Perona
*/
function rocket_activate_custom_login_page_template() {
add_filter( 'rocket_cache_reject_uri', 'rocket_add_custom_login_exclude_pages' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_custom-login-page-template/custom-login-page-template.php', 'rocket_activate_custom_login_page_template', 11 );
/**
* Remove custom login page from excluded urls array on plugin activation
*
* @since 2.7
* @author Remy Perona
*/
function rocket_remove_custom_login_exclude_pages() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_add_custom_login_exclude_pages' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_custom-login-page-template/custom-login-page-template.php', 'rocket_remove_custom_login_exclude_pages', 11 );

View File

@@ -0,0 +1,22 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'DISQUS_VERSION' ) ) :
/**
* Excludes Disqus scripts from JS minification
*
* @since 2.9
* @author Remy Perona
*
* @param Array $excluded_js An array of JS handles enqueued in WordPress.
* @return Array the updated array of handles
*/
function rocket_exclude_js_disqus( $excluded_js ) {
$excluded_js[] = str_replace( home_url(), '', plugins_url( '/disqus-comment-system/media/js/disqus.js' ) );
$excluded_js[] = str_replace( home_url(), '', plugins_url( '/disqus-comment-system/media/js/count.js' ) );
return $excluded_js;
}
add_filter( 'rocket_exclude_js', 'rocket_exclude_js_disqus' );
endif;

View File

@@ -0,0 +1,106 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with Aelia Currency Switcher.
*
* @since 2.7
*/
if ( class_exists( 'WC_Aelia_CurrencySwitcher' ) ) :
/**
* Update .htaccess & config files when the Geolocation option is updated
*
* @since 2.7
*
* @param array $old_value Previous setting values.
* @param array $value Submitted settings values.
*/
function rocket_after_update_aelia_currencyswitcher_options( $old_value, $value ) {
if ( ( ! isset( $old_value['ipgeolocation_enabled'] ) && isset( $value['ipgeolocation_enabled'] ) ) || ( isset( $old_value['ipgeolocation_enabled'], $value['ipgeolocation_enabled'] ) && $old_value['ipgeolocation_enabled'] !== $value['ipgeolocation_enabled'] )
) {
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Update the config file.
rocket_generate_config_file();
}
}
add_action( 'update_option_wc_aelia_currency_switcher', 'rocket_after_update_aelia_currencyswitcher_options', 10, 2 );
/**
* Generate a caching file depending on the currency cookie value
*/
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 64 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_currencyswitcher_dynamic_cookies' );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_aelia_currencyswitcher_mandatory_cookie' );
endif;
/**
* Add the Aelia Currency Switcher cookies when activating the plugin
*
* @since 2.7
*/
function rocket_activate_aelia_currencyswitcher() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 64 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_currencyswitcher_dynamic_cookies' );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_aelia_currencyswitcher_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_woocommerce-aelia-currencyswitcher/woocommerce-aelia-currencyswitcher.php', 'rocket_activate_aelia_currencyswitcher', 11 );
/**
* Remove the Aelia Currency Switcher cookies when deactivating the plugin
*
* @since 2.7
*/
function rocket_deactivate_aelia_currencyswitcher() {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 64 );
remove_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_currencyswitcher_dynamic_cookies' );
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_aelia_currencyswitcher_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_woocommerce-aelia-currencyswitcher/woocommerce-aelia-currencyswitcher.php', 'rocket_deactivate_aelia_currencyswitcher', 11 );
/**
* Add the Aelia Currency Switcher cookies to the dynamic cookies list
*
* @since 2.7
*
* @param array $cookies Cookies to use for dynamic caching.
* @return array Updated cookies list
*/
function rocket_add_aelia_currencyswitcher_dynamic_cookies( $cookies ) {
$cookies[] = 'aelia_cs_recalculate_cart_totals';
$cookies[] = 'aelia_cs_selected_currency';
$cookies[] = 'aelia_customer_country';
return $cookies;
}
/**
* Add the Aelia Currency Switcher to the list of mandatory cookies before generating caching files
*
* @since 2.7
*
* @param array $cookies Mandatory cookies to serve the cache.
* @return array Updated cookies list
*/
function rocket_add_aelia_currencyswitcher_mandatory_cookie( $cookies ) {
$acs_options = get_option( 'wc_aelia_currency_switcher' );
if ( ! empty( $acs_options['ipgeolocation_enabled'] ) ) {
$cookies[] = 'aelia_cs_selected_currency';
}
return $cookies;
}

View File

@@ -0,0 +1,66 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with Aelia Prices by Country.
*
* @since 2.8.15
*/
if ( class_exists( 'Aelia\WC\PricesByCountry\WC_Aelia_Prices_By_Country' ) ) :
/**
* Generate a caching file depending on the country cookie value
*/
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 66 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_prices_by_country_dynamic_cookies' );
endif;
/**
* Add cookie when we activate the plugin
*
* @since 2.8.15
* @author Remy Perona
*/
function rocket_activate_aelia_prices_by_country() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 66 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_prices_by_country_dynamic_cookies' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_woocommerce-prices-by-country/woocommerce-prices-by-country.php', 'rocket_activate_aelia_prices_by_country', 11 );
/**
* Remove cookies when we deactivate the plugin
*
* @since 2.8.15
* @author Remy Perona
*/
function rocket_deactivate_aelia_prices_by_country() {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 66 );
remove_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_prices_by_country_dynamic_cookies' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_woocommerce-prices-by-country/woocommerce-prices-by-country.php', 'rocket_deactivate_aelia_prices_by_country', 11 );
/**
* Add the Aelia Prices by Country cookie to generate caching files depending on its value
*
* @since 2.8.15
* @author Remy Perona
*
* @param array $cookies Cookies list to use for dynamic caching.
* @return array Updated cookies list
*/
function rocket_add_aelia_prices_by_country_dynamic_cookies( $cookies ) {
$cookies[] = 'aelia_customer_country';
return $cookies;
}

View File

@@ -0,0 +1,69 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with Aelia Tax Display by Country.
*
* @since 2.8.15
*/
if ( class_exists( 'Aelia\WC\TaxDisplayByCountry\WC_Aelia_Tax_Display_By_Country' ) ) :
/**
* Generate a caching file depending to the tax display cookie values
*/
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 68 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_tax_display_by_country_dynamic_cookies' );
endif;
/**
* Add cookies when we activate the plugin
*
* @since 2.8.15
* @author Remy Perona
*/
function rocket_activate_aelia_tax_display_by_country() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 68 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_tax_display_by_country_dynamic_cookies' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_woocommerce-tax-display-by-country/woocommerce-tax-display-by-country.php', 'rocket_activate_aelia_tax_display_by_country', 11 );
/**
* Remove cookies when we deactivate the plugin
*
* @since 2.8.15
* @author Remy Perona
*/
function rocket_deactivate_aelia_tax_display_by_country() {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 68 );
remove_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_aelia_tax_display_by_country_dynamic_cookies' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_woocommerce-tax-display-by-country/woocommerce-tax-display-by-country.php', 'rocket_deactivate_aelia_tax_display_by_country', 11 );
/**
* Add the Aelia Tax Display by Country cookies to generate caching files depending on their values
*
* @since 2.8.15
* @author Remy Perona
*
* @param array $cookies Cookies list to use for dynamic caching.
* @return array Updated cookies list
*/
function rocket_add_aelia_tax_display_by_country_dynamic_cookies( $cookies ) {
$cookies[] = 'aelia_customer_country';
$cookies[] = 'aelia_customer_state';
$cookies[] = 'aelia_tax_exempt';
return $cookies;
}

View File

@@ -0,0 +1,52 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( function_exists( 'EDD' ) ) :
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_edd_pages' );
add_action( 'update_option_edd_settings', 'rocket_after_update_array_options', 10, 2 );
endif;
/**
* Exclude EDD pages from cache
*
* @param array $urls Array of URLs to exclude from cache.
* @return array Updated array of URLs
*/
function rocket_exclude_edd_pages( $urls ) {
$edd_settings = get_option( 'edd_settings' );
if ( isset( $edd_settings['purchase_page'] ) ) {
$checkout_urls = get_rocket_i18n_translated_post_urls( $edd_settings['purchase_page'], 'page', '(.*)' );
$urls = array_merge( $urls, $checkout_urls );
}
return $urls;
}
/**
* Exclude EDD pages from cache on EDD activation.
*/
function rocket_activate_edd() {
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_edd_pages' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_easy-digital-downloads/easy-digital-downloads.php', 'rocket_activate_edd', 11 );
/**
* Remove EDD pages from cache exclusion on EDD deactivation.
*/
function rocket_deactivate_edd() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_exclude_edd_pages' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_easy-digital-downloads/easy-digital-downloads.php', 'rocket_deactivate_edd', 11 );

View File

@@ -0,0 +1,58 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with Easy Digital Downloads Software Licensing addon.
*
* @since 2.7
*/
if ( class_exists( 'EDD_Software_Licensing' ) && defined( 'EDD_SL_VERSION' ) ) :
// Exclude EDD SL endpoint from cache on WP Rocket activation.
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_edd_sl_endpoint' );
endif;
/**
* Exclude EDD SL endpoint from cache when activating the plugin
*
* @since 2.7
*/
function rocket_activate_edd_software_licensing() {
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_edd_sl_endpoint' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_edd-software-licensing/edd-software-licenses.php', 'rocket_activate_edd_software_licensing', 11 );
/**
* Remove exclusion of EDD SL endpoint from cache when deactivating the plugin
*
* @since 2.7
*/
function rocket_deactivate_edd_software_licensing() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_exclude_edd_sl_endpoint' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_edd-software-licensing/edd-software-licenses.php', 'rocket_deactivate_edd_software_licensing', 11 );
/**
* Exclude EDD SL endpoint from caching
*
* @since 2.7
*
* @param array $uri URLs to exclude from caching.
* @return array Updated list of URLs to exclude
*/
function rocket_exclude_edd_sl_endpoint( $uri ) {
$uri[] = '/edd-sl/(.*)';
return $uri;
}

View File

@@ -0,0 +1,65 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Exclude pages of Give plugin from cache.
*
* @since 2.7
*/
if ( defined( 'GIVE_VERSION' ) && function_exists( 'give_get_settings' ) ) {
add_filter( 'rocket_cache_reject_uri', 'rocket_add_give_exclude_pages' );
if ( is_admin() ) {
add_action( 'update_option_give_settings', 'rocket_after_update_single_options', 10, 2 );
}
}
/**
* Add give pages to the excluded pages
*
* @since 2.7
*
* @param Array $urls Array of excluded pages.
* @return Array Updated array of excluded pages
*/
function rocket_add_give_exclude_pages( $urls ) {
$give_options = give_get_settings();
$urls = array_merge( $urls, get_rocket_i18n_translated_post_urls( $give_options['success_page'], 'page' ) );
$urls = array_merge( $urls, get_rocket_i18n_translated_post_urls( $give_options['history_page'], 'page' ) );
$urls = array_merge( $urls, get_rocket_i18n_translated_post_urls( $give_options['failure_page'], 'page' ) );
return $urls;
}
/**
* Add give pages to the excluded pages when activating the plugin
*
* @since 2.7
*/
function rocket_activate_give() {
add_filter( 'rocket_cache_reject_uri', 'rocket_add_give_exclude_pages' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_give/give.php', 'rocket_activate_give', 11 );
/**
* Remove give pages from the excluded pages when activating the plugin
*
* @since 2.7
*/
function rocket_remove_give_exclude_pages() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_add_give_exclude_pages' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_give/give.php', 'rocket_remove_give_exclude_pages', 11 );

View File

@@ -0,0 +1,69 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( function_exists( 'it_exchange_get_page_type' ) && function_exists( 'it_exchange_get_page_url' ) ) :
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_ithemes_exchange_pages' );
add_action( 'update_option_it-storage-exchange_settings_pages', 'rocket_after_update_single_options', 10, 2 );
endif;
/**
* Exclude iThemes Exchange pages from cache.
*
* @param array $urls Array of URLs to exclude from cache.
* @return array Updated array of URLs to exclude from cache
*/
function rocket_exclude_ithemes_exchange_pages( $urls ) {
$pages = [
'purchases',
'confirmation',
'account',
'profile',
'downloads',
'purchases',
'log-in',
'log-out',
];
foreach ( $pages as $page ) {
if ( it_exchange_get_page_type( $page ) === 'WordPress' ) {
$exchange_urls = get_rocket_i18n_translated_post_urls( it_exchange_get_page_wpid( $page ) );
} else {
$exchange_urls = [ rocket_extract_url_component( it_exchange_get_page_url( $page ), PHP_URL_PATH ) ];
}
$urls = array_merge( $urls, $exchange_urls );
}
return $urls;
}
/**
* Exclude iThemes Exchanges pages from cache on plugin activation.
*/
function rocket_activate_ithemes_exchange() {
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_ithemes_exchange_pages' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_ithemes-exchange/ithemes-exchange.php', 'rocket_activate_ithemes_exchange', 11 );
/**
* Remove iThemes Exchanges pages from cache exclusion on plugin deactivation.
*/
function rocket_deactivate_ithemes_exchange() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_exclude_ithemes_exchange_pages' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_ithemes-exchange/ithemes-exchange.php', 'rocket_deactivate_ithemes_exchange', 11 );

View File

@@ -0,0 +1,61 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'JIGOSHOP_VERSION' ) && function_exists( 'jigoshop_get_page_id' ) ) :
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_jigoshop_pages' );
add_action( 'update_option_jigoshop_options', 'rocket_after_update_array_options', 10, 2 );
endif;
/**
* Exclude Jigoshop pages from cache.
*
* @param array $urls Array of URLs to exclude from cache.
* @return array Updated array of URLs to exclude from cache
*/
function rocket_exclude_jigoshop_pages( $urls ) {
if ( jigoshop_get_page_id( 'checkout' ) && jigoshop_get_page_id( 'checkout' ) !== '-1' ) {
$checkout_urls = get_rocket_i18n_translated_post_urls( jigoshop_get_page_id( 'checkout' ), 'page', '(.*)' );
$urls = array_merge( $urls, $checkout_urls );
}
if ( jigoshop_get_page_id( 'cart' ) && jigoshop_get_page_id( 'cart' ) !== '-1' ) {
$cart_urls = get_rocket_i18n_translated_post_urls( jigoshop_get_page_id( 'cart' ) );
$urls = array_merge( $urls, $cart_urls );
}
if ( jigoshop_get_page_id( 'myaccount' ) && jigoshop_get_page_id( 'myaccount' ) !== '-1' ) {
$cart_urls = get_rocket_i18n_translated_post_urls( jigoshop_get_page_id( 'myaccount' ), 'page', '(.*)' );
$urls = array_merge( $urls, $cart_urls );
}
return $urls;
}
/**
* Exclude Jigoshop pages from cache on plugin activation.
*/
function rocket_activate_jigoshop() {
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_jigoshop_pages' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_jigoshop/jigoshop.php', 'rocket_activate_jigoshop', 11 );
/**
* Remove Jigoshop pages from cache exclusion on plugin deactivation.
*/
function rocket_deactivate_jigoshop() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_exclude_jigoshop_pages' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_jigoshop/jigoshop.php', 'rocket_deactivate_jigoshop', 11 );

View File

@@ -0,0 +1,83 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with WooCommerce Currency Converter Widget.
*
* @since 2.7
*/
if ( class_exists( 'WC_Currency_Converter' ) ) :
// Add cookie to config file when WP Rocket is activated and WooCommerce Currency Converter Widget is already active.
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 70 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_woocommerce_currency_converter_dynamic_cookies', 11 );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_woocommerce_currency_converter_mandatory_cookie', 11 );
add_action( 'update_option_woocommerce_default_customer_address', 'rocket_after_update_single_options', 10, 2 );
endif;
/**
* Add cookies when we activating the plugin
*
* @since 2.7
*/
function rocket_activate_woocommerce_currency_converter() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 70 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_woocommerce_currency_converter_dynamic_cookies' );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_woocommerce_currency_converter_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_woocommerce-currency-converter-widget/currency-converter.php', 'rocket_activate_woocommerce_currency_converter', 11 );
/**
* Remove cookies when deactivating the plugin
*
* @since 2.7
*/
function rocket_deactivate_woocommerce_currency_converter() {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 70 );
remove_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_woocommerce_currency_converter_dynamic_cookies' );
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_woocommerce_currency_converter_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_woocommerce-currency-converter-widget/currency-converter.php', 'rocket_deactivate_woocommerce_currency_converter', 11 );
/**
* Add the WC Currency Converter Widget cookie to generate caching files depending on its value
*
* @since 2.7
*
* @param array $cookies Cookies list to use for dynamic caching.
* @return array Updated cookies list
*/
function rocket_add_woocommerce_currency_converter_dynamic_cookies( $cookies ) {
$cookies[] = 'woocommerce_current_currency';
return $cookies;
}
/**
* Add the WC Currency Converter Widget cookie to the list of mandatory cookies before generating the caching files
*
* @since 2.7
*
* @param array $cookies Mandatory cookies list.
* @return array Updated cookies list
*/
function rocket_add_woocommerce_currency_converter_mandatory_cookie( $cookies ) {
$widget_woocommerce_currency_converter = get_option( 'widget_woocommerce_currency_converter' );
if ( ! empty( $widget_woocommerce_currency_converter ) && 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) {
$cookies[] = 'woocommerce_current_currency';
}
return $cookies;
}

View File

@@ -0,0 +1,8 @@
<?php
defined( 'ABSPATH' ) || exit;
// Compatibility with the currency switcher in WooCommerce Multilingual plugin.
if ( defined( 'WCML_VERSION' ) ) :
add_action( 'wcml_switch_currency', 'rocket_clean_domain' );
endif;

View File

@@ -0,0 +1,66 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'WPSHOP_VERSION' ) && class_exists( 'wpshop_tools' ) && method_exists( 'wpshop_tools', 'get_page_id' ) ) :
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_wpshop_pages' );
add_action( 'update_option_wpshop_cart_page_id', 'rocket_after_update_single_options', 10, 2 );
add_action( 'update_option_wpshop_checkout_page_id', 'rocket_after_update_single_options', 10, 2 );
add_action( 'update_option_wpshop_payment_return_page_id', 'rocket_after_update_single_options', 10, 2 );
add_action( 'update_option_wpshop_payment_return_nok_page_id', 'rocket_after_update_single_options', 10, 2 );
add_action( 'update_option_wpshop_myaccount_page_id', 'rocket_after_update_single_options', 10, 2 );
endif;
/**
* Exclude WP Shop pages from cache.
*
* @param array $urls Array of URLs to exclude from cache.
* @return array Updated array of URLs to exclude from cache
*/
function rocket_exclude_wpshop_pages( $urls ) {
$pages = [
'wpshop_cart_page_id',
'wpshop_checkout_page_id',
'wpshop_payment_return_page_id',
'wpshop_payment_return_nok_page_id',
'wpshop_myaccount_page_id',
];
foreach ( $pages as $page ) {
$page_id = wpshop_tools::get_page_id( get_option( $page ) );
if ( $page_id ) {
$urls = array_merge( $urls, get_rocket_i18n_translated_post_urls( $page_id ) );
}
}
return $urls;
}
/**
* Exclude WP Shop pages from cache on plugin activation.
*/
function rocket_activate_wpshop() {
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_wpshop_pages' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_wpshop/wpshop.php', 'rocket_activate_wpshop', 11 );
/**
* Remove WP Shop pages from cache exclusion on plugin deactivation.
*/
function rocket_deactivate_wpshop() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_exclude_wpshop_pages' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_wpshop/wpshop.php', 'rocket_deactivate_wpshop', 11 );

View File

@@ -0,0 +1,33 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Conflict with Envira Gallery: don't apply LazyLoad on all images
*
* @since 2.3.10
*
* @param string $attr Envira gallery image attributes.
* @return string Updated attributes
*/
function rocket_deactivate_lazyload_on_envira_gallery( $attr ) {
return $attr . ' data-no-lazy="1" ';
}
add_filter( 'envira_gallery_output_image_attr', 'rocket_deactivate_lazyload_on_envira_gallery', PHP_INT_MAX );
/**
* Conflict with Envira Gallery: don't apply LazyLoad on all images
*
* @since 2.3.10
*
* @param string $images Envira gallery images HTML code.
* @return string Updated HTML code
*/
function rocket_deactivate_lazyload_on_envira_gallery_indexable_images( $images ) {
$images = str_replace( '<img', '<img data-no-lazy="1" ', $images );
return $images;
}
add_filter( 'envira_gallery_indexable_images', 'rocket_deactivate_lazyload_on_envira_gallery_indexable_images', PHP_INT_MAX );

View File

@@ -0,0 +1,115 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Compatibility with GeotargetingWP Plugins
*
* @author Damian Logghe <info@timersys.com>
*/
if ( class_exists( 'GeotWP\GeotargetingWP' ) ) :
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 72 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_geotargetingwp_dynamic_cookies' );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_geotargetingwp_mandatory_cookie' );
/**
* If we recently deactivated a plugin of the family but
* we still see the class it means another plugin is still active,
* so flush rules once more to be safe
*/
if ( get_option( 'geotWP-deactivated' ) ) {
// Update the WP Rocket rules on the .htaccess file.
add_action( 'admin_init', 'flush_rocket_htaccess' );
// Regenerate the config file.
add_action( 'admin_init', 'rocket_generate_config_file' );
delete_option( 'geotWP-deactivated' );
}
endif;
/**
* Add cookies when we activate any goetargetingWP plugin.
*
* @since 2.10.3
* @author Damian Logghe
*/
function rocket_activate_geotargetingwp() {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 72 );
add_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_geotargetingwp_dynamic_cookies' );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_geotargetingwp_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'geotWP/activated', 'rocket_activate_geotargetingwp', 11 );
/**
* Remove cookies when we deactivate the plugin.
*
* @since 2.10.3
* @author Damian Logghe
*/
function rocket_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', '__return_false', 72 );
remove_filter( 'rocket_cache_dynamic_cookies', 'rocket_add_geotargetingwp_dynamic_cookies' );
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_geotargetingwp_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'geotWP/deactivated', 'rocket_deactivate_geotargetingwp', 11 );
/**
* Add the GeotargetingWP cookies to generate caching files depending on their values.
*
* @since 2.10.3
* @author Damian Logghe
*
* @param Array $cookies An array of cookies.
* @return Array Updated array of cookies
*/
function rocket_add_geotargetingwp_dynamic_cookies( $cookies ) {
return rocket_add_geot_cookies( $cookies );
}
/**
* Add the GeotargetingWP cookies to the list of mandatory cookies before to generate caching files.
*
* @since 2.10.3
* @author Damian Logghe
*
* @param Array $cookies An array of cookies.
* @return Array Updated array of cookies
*/
function rocket_add_geotargetingwp_mandatory_cookie( $cookies ) {
return rocket_add_geot_cookies( $cookies );
}
/**
* Let users modify cache level by default set to country.
*
* @since 2.10.3
* @author Damian Logghe
*
* @param Array $cookies An array of cookies.
* @return Array Updated array of cookies
*/
function rocket_add_geot_cookies( $cookies ) {
// valid options are country, state, city.
$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;
}

View File

@@ -0,0 +1,145 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'POLYLANG_VERSION' ) && POLYLANG_VERSION ) :
/**
* Conflict with Polylang: Clear the whole cache when the "The language is set from content" option is activated.
*
* @since 2.6.8
*/
function rocket_force_clean_domain_on_polylang() {
$pll = function_exists( 'PLL' ) ? PLL() : $GLOBALS['polylang'];
if ( isset( $pll ) && 0 === $pll->options['force_lang'] ) {
rocket_clean_cache_dir();
}
}
add_action( 'after_rocket_clean_domain', 'rocket_force_clean_domain_on_polylang' );
// Filter mandatory cookies and WP Rocket rewrite rules if Polylang module 'Detect browser language' is enabled.
if ( function_exists( 'PLL' ) && PLL()->options['browser'] ) {
// Add Polylang's language cookie as a mandatory cookie.
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_polylang_mandatory_cookie' );
// Remove WP Rocket rewrite rules from .htaccess file.
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 74 );
}
endif;
/**
* Add Polylang's language cookie to the mandatory cookies of WP Rocket.
*
* Polylang saves the users preferred language in this cookie by detecting browser language or by user choice
* Adding this as a mandatory cookie prevents WP Rocket from serving the cache when the cookie is not set.
*
* @param array $cookies Array with mandatory cookies.
* @return (array) Array of mandatory cookies with the Polylang cookie appended
*
* @author Arun Basil Lal
* @since 3.0.5
*/
function rocket_add_polylang_mandatory_cookie( $cookies ) {
$cookies[] = defined( 'PLL_COOKIE' ) ? PLL_COOKIE : 'pll_language';
return $cookies;
}
/**
* Add mandatory cookie to WP Rocket config and remove rewrite rules from .htaccess on Polylang activation.
*
* Add mandatory cookie only if the Polylang module 'Detect browser language' is active.
* Also purge the homepage cache.
*
* @author Arun Basil Lal
* @since 3.0.5
*/
function rocket_activate_polylang() {
// Read Polylang settings from db.
$polylang_settings = get_option( 'polylang' );
if ( isset( $polylang_settings['browser'] ) && ( 1 === (int) $polylang_settings['browser'] ) ) {
// Add Polylang's language cookie as a mandatory cookie.
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_polylang_mandatory_cookie' );
// Remove WP Rocket rewrite rules from .htaccess file.
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 74 );
// Regenerate the config file.
rocket_generate_config_file();
// Regenerate .htaccess file.
flush_rocket_htaccess();
// Purge homepage cache.
rocket_clean_home();
}
}
add_action( 'activate_polylang/polylang.php', 'rocket_activate_polylang', 11 );
/**
* Remove mandatory cookie and add rewrite rules back to .htaccess when Polylang is deactivated.
*
* @author Arun Basil Lal
* @since 3.0.5
*/
function rocket_deactivate_polylang() {
// Remove Polylang's language cookie as a mandatory cookie.
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_polylang_mandatory_cookie' );
// Add back WP Rocket rewrite rules from .htaccess file.
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 74 );
// Regenerate the config file.
rocket_generate_config_file();
// Regenerate .htaccess file.
flush_rocket_htaccess();
}
add_action( 'deactivate_polylang/polylang.php', 'rocket_deactivate_polylang', 11 );
/**
* Update mandatory cookie in WP Rocket config file and remove rewrite rules from .htaccess
* when Detect browser language module is enabled / disabled.
*
* @param array $value Array containing Polylang settings before its written to db.
* @return array
*
* @author Arun Basil Lal
* @since 3.0.5
*/
function rocket_detect_browser_language_status_change( $value ) {
if ( function_exists( 'PLL' ) && PLL()->options['browser'] ) {
// Add Polylang's language cookie as a mandatory cookie.
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_polylang_mandatory_cookie' );
// Remove WP Rocket rewrite rules from .htaccess file.
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 74 );
// Regenerate the config file.
rocket_generate_config_file();
// Regenerate .htaccess file.
flush_rocket_htaccess();
// Purge homepage cache.
rocket_clean_home();
} else {
// Remove Polylang's language cookie as a mandatory cookie.
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_polylang_mandatory_cookie' );
// Add back WP Rocket rewrite rules from .htaccess file.
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 74 );
// Regenerate the config file.
rocket_generate_config_file();
// Regenerate .htaccess file.
flush_rocket_htaccess();
}
return $value;
}
add_filter( 'pre_update_option_polylang', 'rocket_detect_browser_language_status_change' );

View File

@@ -0,0 +1,11 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'ICL_SITEPRESS_VERSION' ) && ICL_SITEPRESS_VERSION ) :
/**
* Tell WooCommerce Multilingual that we are caching.
* This will add a URL param when switching currency to get the correct response.
*/
add_filter( 'wcml_is_cache_enabled_for_switching_currency', '__return_true' );
endif;

View File

@@ -0,0 +1,187 @@
<?php
/**
* Compatibility file with the Jetpack plugin.
* https://wordpress.org/plugins/jetpack/
*
* @package WP Rocket
*/
defined( 'ABSPATH' ) || exit;
// Is Jetpack installed and active?
if ( class_exists( 'Jetpack' ) ) :
/**
* Improvement with Jetpack: auto-detect the XML sitemaps for the preload option
*
* @since 2.8
* @author Remy Perona
*/
if (
Jetpack::is_module_active( 'sitemaps' )
&& function_exists( 'jetpack_sitemap_uri' )
) {
/**
* Add Jetpack option to WP Rocket options
*
* @since 2.8
* @author Remy Perona
*
* @param Array $options WP Rocket options array.
* @return Array Updated WP Rocket options array
*/
function rocket_add_jetpack_sitemap_option( $options ) {
$options['jetpack_xml_sitemap'] = 0;
return $options;
}
add_filter( 'rocket_first_install_options', 'rocket_add_jetpack_sitemap_option' );
/**
* Sanitize jetpack option value
*
* @since 2.8
* @author Remy Perona
*
* @param Array $inputs Array of inputs values.
* @return Array Array of inputs values
*/
function rocket_jetpack_sitemap_option_sanitize( $inputs ) {
$inputs['jetpack_xml_sitemap'] = ! empty( $inputs['jetpack_xml_sitemap'] ) ? 1 : 0;
return $inputs;
}
add_filter( 'rocket_inputs_sanitize', 'rocket_jetpack_sitemap_option_sanitize' );
/**
* Add Jetpack sitemap to preload list
*
* @since 2.8
* @author Remy Perona
*
* @param Array $sitemaps Array of sitemaps to preload.
* @return Array Updated Array of sitemaps to preload
*/
function rocket_add_jetpack_sitemap( $sitemaps ) {
if ( get_rocket_option( 'jetpack_xml_sitemap', false ) ) {
$sitemaps['jetpack'] = jetpack_sitemap_uri();
}
return $sitemaps;
}
add_filter( 'rocket_sitemap_preload_list', 'rocket_add_jetpack_sitemap' );
/**
* Add Jetpack sub-option to WP Rocket settings page
*
* @since 2.8
* @author Remy Perona
*
* @param Array $options WP Rocket options array.
* @return Array Updated WP Rocket options array
*/
function rocket_sitemap_preload_jetpack_option( $options ) {
$options[] = [
'parent' => 'sitemap_preload',
'type' => 'checkbox',
'label' => __( 'Jetpack XML Sitemaps', 'rocket' ),
'label_for' => 'jetpack_xml_sitemap',
'label_screen' => sprintf( __( 'Preload the sitemap from the Jetpack plugin', 'rocket' ), 'Jetpack' ),
'default' => 0,
];
$options[] = [
'parent' => 'sitemap_preload',
'type' => 'helper_description',
'name' => 'jetpack_xml_sitemap_desc',
// translators: %s = plugin name, e.g. Yoast SEO.
'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Jetpack' ),
];
return $options;
}
add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_preload_jetpack_option' );
} // End if().
/**
* Support Jetpack's EU Cookie Law Widget.
*
* @see https://jetpack.com/support/extra-sidebar-widgets/eu-cookie-law-widget/
*
* @since 2.10.1
* @author Jeremy Herve
*/
if ( Jetpack::is_module_active( 'widgets' ) ) :
/**
* Add the EU Cookie Law to the list of mandatory cookies before generating caching files.
*
* @since 2.10.1
* @author Jeremy Herve
*
* @param array $cookies List of mandatory cookies.
*/
function rocket_add_jetpack_cookie_law_mandatory_cookie( $cookies ) {
$cookies['jetpack-eu-cookie-law'] = 'eucookielaw';
return $cookies;
}
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_jetpack_cookie_law_mandatory_cookie' );
// Don't add the WP Rocket rewrite rules to avoid issues.
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 76 );
/**
* Add Jetpack cookie when:
* - Jetpack is active.
* - Jetpack's Extra Sidebar Widgets module is active.
* - The widget is active.
* - the rocket_jetpack_eu_cookie_widget option is empty or not set.
*
* @since 2.10.1
* @author Jeremy Herve
*/
function rocket_activate_jetpack_cookie_law() {
$rocket_jp_eu_cookie_widget = get_option( 'rocket_jetpack_eu_cookie_widget' );
if (
is_active_widget( false, false, 'eu_cookie_law_widget' )
&& empty( $rocket_jp_eu_cookie_widget )
) {
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 76 );
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_jetpack_cookie_law_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
// Set the option, so this is not triggered again.
update_option( 'rocket_jetpack_eu_cookie_widget', 1, true );
}
}
add_action( 'admin_init', 'rocket_activate_jetpack_cookie_law' );
endif; // End if Widgets module is active check.
endif; // End if Jetpack is active check.
/**
* Remove cookies if Jetpack gets deactivated.
*
* @since 2.10.1
* @author Jeremy Herve
*/
function rocket_remove_jetpack_cookie_law_mandatory_cookie() {
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 76 );
remove_filter( 'rocket_cache_mandatory_cookies', '_rocket_add_eu_cookie_law_mandatory_cookie' );
// Update the WP Rocket rules on the .htaccess file.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
// Delete our option.
delete_option( 'rocket_jetpack_eu_cookie_widget' );
}
add_action( 'deactivate_jetpack/jetpack.php', 'rocket_remove_jetpack_cookie_law_mandatory_cookie', 11 );

View File

@@ -0,0 +1,36 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Conflict with MailChimp List Subscribe Form: Enqueue style without lack of performance, grrrr!!!
*
* @since 2.6
*/
function rocket_fix_mailchimp_main_css() {
if ( ! defined( 'MCSF_VER' ) || ! function_exists( 'mailchimpSF_main_css' ) ) {
return;
}
$blog_id = get_current_blog_id();
$cache_path = WP_ROCKET_MINIFY_CACHE_PATH . $blog_id . '/';
$cache_url = WP_ROCKET_MINIFY_CACHE_URL . $blog_id . '/';
$css_path = $cache_path . 'mailchimpSF_main_css.css';
if ( ! rocket_direct_filesystem()->is_dir( $cache_path ) ) {
rocket_mkdir_p( $cache_path );
}
if ( ! rocket_direct_filesystem()->exists( $css_path ) ) {
ob_start();
mailchimpSF_main_css();
$content = ob_get_contents();
ob_end_clean();
rocket_put_content( $css_path, $content );
}
wp_deregister_style( 'mailchimpSF_main_css' );
wp_register_style( 'mailchimpSF_main_css', $cache_url . 'mailchimpSF_main_css.css', null, MCSF_VER );
}
add_action( 'init', 'rocket_fix_mailchimp_main_css', PHP_INT_MAX );

View File

@@ -0,0 +1,56 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'WpAppKit' ) ) :
add_filter( 'rocket_cache_reject_uri', 'rocket_add_appkit_exclude_pages' );
endif;
/**
* Add WP Appkit path to cache exclusion
*
* @since 2.9
* @author Remy Perona
*
* @param array $urls URLs to exclude from cache.
* @return array Updated URLs array
*/
function rocket_add_appkit_exclude_pages( $urls ) {
$urls[] = '/wp-appkit-api/(.*)';
return $urls;
}
/**
* Add WP Appkit path to cache exclusion when activating the plugin
*
* @since 2.9
* @author Remy Perona
*/
function rocket_activate_wp_appkit() {
add_filter( 'rocket_cache_reject_uri', 'rocket_add_appkit_exclude_pages' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'activate_wp-appkit/wp-appkit.php', 'rocket_activate_wp_appkit', 11 );
/**
* Remove Appkit path from cache exclusion when deactivating the plugin
*
* @since 2.9
* @author Remy Perona
*/
function rocket_deactivate_wp_appkit() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_add_appkit_exclude_pages' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'deactivate_wp-appkit/wp-appkit.php', 'rocket_deactivate_wp_appkit', 11 );

View File

@@ -0,0 +1,149 @@
<?php
defined( 'ABSPATH' ) || exit;
global $nginx_helper;
if ( isset( $nginx_helper ) ) :
global $nginx_purger;
/**
* Clear WP Rocket cache after the NGINX cache is purged from Nginx Helper.
*
* @since 3.3.0.1
*
* @return void
*/
function rocket_clear_cache_after_nginx_helper_purge() {
if ( ! isset( $_GET['nginx_helper_action'] ) ) {
return;
}
if ( ! check_admin_referer( 'nginx_helper-purge_all' ) ) {
return;
}
if ( 'done' !== sanitize_text_field( wp_unslash( $_GET['nginx_helper_action'] ) ) ) {
return;
}
if ( ! current_user_can( 'rocket_purge_cache' ) ) {
return;
}
// Clear all caching files.
rocket_clean_domain();
}
add_action( 'admin_init', 'rocket_clear_cache_after_nginx_helper_purge' );
/**
* Clear WP Rocket cache for the current page after the NGINX cache is purged from Nginx Helper.
*
* @since 3.3.0.1
*
* @return void
*/
function rocket_clear_current_page_after_nginx_helper_purge() {
if ( ! isset( $_GET['nginx_helper_action'], $_GET['_wpnonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'nginx_helper-purge_all' ) ) {
return;
}
if ( is_admin() ) {
return;
}
if ( ! current_user_can( 'rocket_purge_posts' ) ) {
return;
}
$referer = wp_get_referer();
if ( 0 !== strpos( $referer, 'http' ) ) {
$parse_url = get_rocket_parse_url( untrailingslashit( home_url() ) );
$referer = $parse_url['scheme'] . '://' . $parse_url['host'] . $referer;
}
if ( home_url( '/' ) === $referer ) {
rocket_clean_home();
return;
}
rocket_clean_files( $referer );
}
add_action( 'init', 'rocket_clear_current_page_after_nginx_helper_purge' );
/**
* Clears NGINX cache for the homepage URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.3.0.1
* @author Remy Perona
*
* @param string $root WP Rocket root cache path.
* @param string $lang Current language.
* @return void
*/
function rocket_clean_nginx_cache_home( $root = '', $lang = '' ) {
global $nginx_purger;
if ( ! isset( $nginx_purger ) ) {
return;
}
$url = get_rocket_i18n_home_url( $lang );
$nginx_purger->purge_url( $url );
}
add_action( 'after_rocket_clean_home', 'rocket_clean_nginx_cache_home', 10, 2 );
/**
* Clears NGINX cache for a specific URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.3.0.1
* @author Remy Perona
*
* @param string $url URL to purge.
* @return void
*/
function rocket_clean_nginx_cache_url( $url ) {
global $nginx_purger;
if ( ! isset( $nginx_purger ) ) {
return;
}
if ( ! isset( $_GET['type'], $_GET['_wpnonce'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
if ( false !== strpos( $url, 'index.html' ) ) {
return;
}
if ( 'page' === substr( $url, -4 ) ) {
return;
}
$url = str_replace( '*', '', $url );
$nginx_purger->purge_url( $url );
}
add_action( 'after_rocket_clean_file', 'rocket_clean_nginx_cache_url' );
/**
* Clean the NGINX cache using Nginx Helper after WP Rocket's cache is purged.
*
* @since 3.3.0.1
*/
function rocket_clean_nginx_helper_cache() {
if ( isset( $_GET['nginx_helper_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
do_action( 'rt_nginx_helper_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_nginx_helper_cache' );
endif;

View File

@@ -0,0 +1,16 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( function_exists( 'tve_editor_url' ) ) {
/**
* Forces Thrive Visual Editors bot detection to assume a human visitor.
*
* @since 2.8.11
* @author Remy Perona
*
* @param boolean|integer $bot_detection 1|0 when crawler has|not been detected, FALSE when user agent string is unavailable
* @return integer
*/
add_filter( 'tve_dash_is_crawler', '__return_zero', PHP_INT_MAX );
}

View File

@@ -0,0 +1,10 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'WPB_VC_VERSION' ) && class_exists( 'Vc_Manager' ) ) :
/**
* Disable nonce checking for Visual Composer grid
*/
add_filter( 'vc_grid_get_grid_data_access', '__return_true' );
endif;

View File

@@ -0,0 +1,17 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'BhittaniPlugin_kkStarRatings' ) ) :
/**
* Conflict with kk Star Ratings: Clear the cache when a post gets rated.
*
* @since 2.5.3
*
* @param int $post_id Post ID.
*/
function rocket_clear_cache_on_kksr_rate( $post_id ) {
rocket_clean_post( $post_id );
}
add_action( 'kksr_rate', 'rocket_clear_cache_on_kksr_rate' );
endif;

View File

@@ -0,0 +1,18 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'WP_POSTRATINGS_VERSION' ) ) :
/**
* Conflict with WP-PostRatings: Clear the cache when a post gets rated.
*
* @since 2.6.6
*
* @param int $user_id user ID.
* @param int $post_id post ID.
*/
function rocket_clear_cache_on_wp_postratings_rate( $user_id, $post_id ) {
rocket_clean_post( $post_id );
}
add_action( 'rate_post', 'rocket_clear_cache_on_wp_postratings_rate', 10, 2 );
endif;

View File

@@ -0,0 +1,18 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Excludes s2 Member dynamic file from saving as static resource
*
* @since 2.11.4
* @author Remy Perona
*
* @param array $excluded_files Array of excluded files.
*/
function rocket_exclude_s2member_dynamic_files( $excluded_files ) {
$excluded_files[] = rocket_clean_exclude_file( plugins_url( '/s2member/s2member-o.php' ) );
return $excluded_files;
}
add_action( 'rocket_exclude_static_dynamic_resources', 'rocket_exclude_s2member_dynamic_files' );

View File

@@ -0,0 +1,90 @@
<?php
defined( 'ABSPATH' ) || exit;
add_action( 'update_option_secupress_users-login_settings', 'rocket_after_update_single_options', 10, 2 );
/**
* Add SecuPress move login pages to cache exclusion
*
* @since 2.9
* @author Remy Perona
*
* @param array $urls URLs to exclude from cache.
* @return array Updated URLs to exclude
*/
function rocket_exclude_secupress_move_login( $urls ) {
if ( ! function_exists( 'secupress_move_login_get_slugs' ) ) {
return $urls;
}
$bases = secupress_get_rewrite_bases();
$slugs = secupress_move_login_get_slugs();
foreach ( $slugs as $slug ) {
$urls[] = $bases['base'] . ltrim( $bases['site_from'], '/' ) . $slug . '/?';
}
return $urls;
}
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_secupress_move_login' );
/**
* Add SecuPress move login pages to cache exclusion when activating the plugin
*
* @since 2.9
* @author Remy Perona
*/
function rocket_maybe_activate_secupress() {
if ( function_exists( 'secupress_move_login_get_slugs' ) ) {
rocket_activate_secupress();
}
}
add_action( 'secupress.plugins.activation', 'rocket_maybe_activate_secupress', 10001 );
/**
* Add SecuPress move login pages to cache exclusion when activating the move login module
*
* @since 2.9
* @author Remy Perona
*/
function rocket_activate_secupress() {
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_secupress_move_login' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'secupress.plugin.move_login.activate', 'rocket_activate_secupress' );
/**
* Remove SecuPress move login pages from cache exclusion when deactivating the plugin
*
* @since 2.9
* @author Remy Perona
*/
function rocket_maybe_deactivate_secupress() {
if ( function_exists( 'secupress_move_login_get_slugs' ) ) {
rocket_deactivate_secupress();
}
}
add_action( 'secupress.deactivation', 'rocket_maybe_deactivate_secupress', 10001 );
/**
* Remove SecuPress move login pages from cache exclusion when deactivating the move login module
*
* @since 2.9
* @author Remy Perona
*/
function rocket_deactivate_secupress() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_exclude_secupress_move_login' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
add_action( 'secupress.plugin.move_login.deactivate', 'rocket_deactivate_secupress' );

View File

@@ -0,0 +1,82 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'SFML_VERSION' ) ) :
add_filter( 'rocket_cache_reject_uri', 'rocket_add_sfml_exclude_pages' );
add_action( 'update_option_sfml', 'rocket_after_update_single_options', 10, 2 );
endif;
/**
* Exclude SF Move Login custom urls from caching
*
* @since 2.9.3 Moved to 3rd party file and improved
* @since 2.6
*
* @param array $urls An array of URLs to exclude from cache.
* @return array Updated array of URLs
*/
function rocket_add_sfml_exclude_pages( $urls ) {
if ( ! function_exists( 'sfml_get_slugs' ) ) {
if ( file_exists( SFML_PLUGIN_DIR . 'inc/utilities.php' ) ) {
include SFML_PLUGIN_DIR . 'inc/utilities.php';
} else {
return $urls;
}
}
if ( ! class_exists( 'SFML_Options' ) && ! defined( 'SFML_NOOP_VERSION' ) ) {
if ( file_exists( SFML_PLUGIN_DIR . 'inc/class-sfml-options.php' ) ) {
include SFML_PLUGIN_DIR . 'inc/class-sfml-options.php';
} else {
return $urls;
}
}
$sfml_slugs = sfml_get_slugs();
$sfml_slugs = array_map( 'home_url', $sfml_slugs );
$sfml_slugs = array_map( 'trailingslashit', $sfml_slugs );
$sfml_slugs = array_map( 'rocket_clean_exclude_file', $sfml_slugs );
foreach ( $sfml_slugs as $key => $slug ) {
$sfml_slugs[ $key ] = $slug . '?';
}
return array_merge( $urls, $sfml_slugs );
}
/**
* Add SFML custom urls to caching exclusion when activating the plugin
*
* @since 2.9.3
*/
function rocket_activate_sfml() {
if ( defined( 'SFML_VERSION' ) ) {
add_filter( 'rocket_cache_reject_uri', 'rocket_add_sfml_exclude_pages' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
}
add_action( 'activate_sf-move-login/sf-move-login.php', 'rocket_activate_sfml', 11 );
/**
* Remove SFML custom urls from caching exclusion when deactivating the plugin
*
* @since 2.9.3
*/
function rocket_deactivate_sfml() {
if ( defined( 'SFML_VERSION' ) ) {
remove_filter( 'rocket_cache_reject_uri', 'rocket_add_sfml_exclude_pages' );
// Update the WP Rocket rules on the .htaccess.
flush_rocket_htaccess();
// Regenerate the config file.
rocket_generate_config_file();
}
}
add_action( 'deactivate_sf-move-login/sf-move-login.php', 'rocket_deactivate_sfml', 11 );

View File

@@ -0,0 +1,62 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'WPS_Hide_Login' ) || defined( 'WPS_HIDE_LOGIN_VERSION' ) ) :
add_action( 'update_option_whl_page', 'rocket_after_update_single_options', 10, 2 );
add_filter( 'rocket_cache_reject_uri', 'rocket_exlude_wps_hide_login_page' );
endif;
/**
* Exclude WPS Hide Login custom url from caching
*
* @since 3.1 Switch implementation depending on the WPS Hide Login version
* @since 2.11.7 Login url is retrieved using new_login_url() method of WPS_Hide_Login() class.
* @since 2.11 Moved to 3rd party file
* @since 2.6
*
* @param array $urls An array of URLs to exclude from cache.
* @return array Updated array of URLs
*/
function rocket_exlude_wps_hide_login_page( $urls ) {
if ( class_exists( 'WPS_Hide_Login' ) ) {
$wps_hide_login = new WPS_Hide_Login();
$urls[] = rocket_clean_exclude_file( $wps_hide_login->new_login_url() );
} elseif ( class_exists( '\WPS\WPS_Hide_Login\Plugin' ) ) {
$urls[] = rocket_clean_exclude_file( \WPS\WPS_Hide_Login\Plugin::get_instance()->new_login_url() );
}
return $urls;
}
/**
* Add WPS Hide Login custom url to caching exclusion when activating the plugin
*
* @since 2.11
*/
function rocket_activate_wps_hide_login() {
add_filter( 'rocket_cache_reject_uri', 'rocket_exlude_wps_hide_login_page' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Update config file.
rocket_generate_config_file();
}
add_action( 'activate_wps-hide-login/wps-hide-login.php', 'rocket_activate_wps_hide_login', 11 );
/**
* Remove WPS Hide Login custom url from caching exclusion when deactivating the plugin
*
* @since 2.11
*/
function rocket_deactivate_wps_hide_login() {
remove_filter( 'rocket_cache_reject_uri', 'rocket_exlude_wps_hide_login_page' );
// Update .htaccess file rules.
flush_rocket_htaccess();
// Update config file.
rocket_generate_config_file();
}
add_action( 'deactivate_wps-hide-login/wps-hide-login.php', 'rocket_deactivate_wps_hide_login', 11 );

View File

@@ -0,0 +1,101 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'AIOSEOP_VERSION' ) ) :
$aioseosp_options = get_option( 'aioseop_options' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
/**
* Improvement with All in One SEO Pack: auto-detect the XML sitemaps for the preload option
*
* @since 2.8
* @author Remy Perona
*/
if ( isset( $aioseosp_options['modules']['aiosp_feature_manager_options']['aiosp_feature_manager_enable_sitemap'] ) && 'on' === $aioseosp_options['modules']['aiosp_feature_manager_options']['aiosp_feature_manager_enable_sitemap'] ) {
/**
* Add All in One SEO Sitemap option to WP Rocket options
*
* @since 2.8
* @author Remy Perona
*
* @param Array $options Array of WP Rocket options.
* @return Array Updated array of WP Rocket options
*/
function rocket_add_all_in_one_seo_sitemap_option( $options ) {
$options['all_in_one_seo_xml_sitemap'] = 0;
return $options;
}
add_filter( 'rocket_first_install_options', 'rocket_add_all_in_one_seo_sitemap_option' );
/**
* Sanitize the AIO SEO option value
*
* @since 2.8
* @author Remy Perona
*
* @param Array $inputs Array of inputs values.
* @return Array Updated array of inputs $values
*/
function rocket_all_in_one_seo_sitemap_option_sanitize( $inputs ) {
$inputs['all_in_one_seo_xml_sitemap'] = ! empty( $inputs['all_in_one_seo_xml_sitemap'] ) ? 1 : 0;
return $inputs;
}
add_filter( 'rocket_inputs_sanitize', 'rocket_all_in_one_seo_sitemap_option_sanitize' );
/**
* Add All in One SEO Sitemap to the preload list
*
* @since 2.8
* @author Remy Perona
*
* @param Array $sitemaps Array of sitemaps to preload.
* @return Array Updated array of sitemaps to preload
*/
function rocket_add_all_in_one_seo_sitemap( $sitemaps ) {
if ( ! get_rocket_option( 'all_in_one_seo_xml_sitemap', false ) ) {
return $sitemaps;
}
$aioseosp_options = get_option( 'aioseop_options' );
if ( ! isset( $aioseosp_options['modules']['aiosp_feature_manager_options']['aiosp_feature_manager_enable_sitemap'] ) || 'on' !== $aioseosp_options['modules']['aiosp_feature_manager_options']['aiosp_feature_manager_enable_sitemap'] ) {
return $sitemaps;
}
$sitemaps[] = trailingslashit( home_url() ) . apply_filters( 'aiosp_sitemap_filename', 'sitemap' ) . '.xml'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
return $sitemaps;
}
add_filter( 'rocket_sitemap_preload_list', 'rocket_add_all_in_one_seo_sitemap' );
/**
* Add All in One SEO Sitemap sub-option on WP Rocket settings page
*
* @since 2.8
* @author Remy Perona
*
* @param Array $options Array of WP Rocket options.
* @return Array Updated array of WP Rocket options
*/
function rocket_sitemap_preload_all_in_one_seo_option( $options ) {
$options['all_in_one_seo_xml_sitemap'] = [
'type' => 'checkbox',
'container_class' => [
'wpr-field--children',
],
'label' => __( 'All in One SEO XML sitemap', 'rocket' ),
// translators: %s = Name of the plugin.
'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'All in One SEO' ),
'parent' => 'sitemap_preload',
'section' => 'preload_section',
'page' => 'preload',
'default' => 0,
'sanitize_callback' => 'sanitize_checkbox',
];
return $options;
}
add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_preload_all_in_one_seo_option' );
}
endif;

View File

@@ -0,0 +1,30 @@
<?php
/**
* Compatibility with Premium SEO Pack
*
* @link http://premiumseopack.com
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'psp' ) ) {
/**
* Dequeue the stylesheet of Premium SEO Pack on WP Rocket settings page.
*
* @since 2.11.6
* @author Arun Basil Lal
*/
function rocket_dequeue_premium_seo_pack_stylesheet() {
// Retun on all pages but WP Rocket settings page.
$screen = get_current_screen();
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
// Dequeueing this stylesheet unfreezes WP Rocket.
wp_dequeue_style( 'psp-main-style' );
}
add_action( 'admin_print_styles', 'rocket_dequeue_premium_seo_pack_stylesheet', 11 );
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* The wp-rocket compatibility functionality.
*
* @since 3.2.3
* @package Rank Math
* @subpackage RankMath\Compatibility
* @author MyThemeShop <admin@mythemeshop.com>
*/
defined( 'ABSPATH' ) || exit;
// Ealry Bail!!
if ( ! defined( 'RANK_MATH_FILE' ) || ! \RankMath\Helper::is_module_active( 'sitemap' ) ) {
return;
}
/**
* Add sitemap option to WP Rocket settings
*
* @since 3.2.3
*
* @param array $options WP Rocket settings array.
* @return array Updated WP Rocket settings array
*/
function rank_math_rocket_sitemap_preload_option( $options ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$options['rank_math_xml_sitemap'] = [
'type' => 'checkbox',
'container_class' => [
'wpr-field--children',
],
'label' => __( 'Rank Math XML sitemap', 'rocket' ),
// translators: %s = Name of the plugin.
'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Rank Math SEO' ),
'parent' => 'sitemap_preload',
'section' => 'preload_section',
'page' => 'preload',
'default' => 0,
'sanitize_callback' => 'sanitize_checkbox',
];
return $options;
}
add_filter( 'rocket_sitemap_preload_options', 'rank_math_rocket_sitemap_preload_option' );
/**
* Add sitemap option to WP Rocket default options
*
* @since 3.2.3
*
* @param array $options WP Rocket options array.
* @return array Updated WP Rocket options array
*/
function rank_math_rocket_add_sitemap_option( $options ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$options['rank_math_xml_sitemap'] = 0;
return $options;
}
add_filter( 'rocket_first_install_options', 'rank_math_rocket_add_sitemap_option' );
/**
* Sanitize SEO sitemap option value
*
* @since 3.2.3
*
* @param array $inputs WP Rocket inputs array.
* @return array Sanitized WP Rocket inputs array
*/
function rank_math_rocket_sitemap_option_sanitize( $inputs ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$inputs['rank_math_xml_sitemap'] = ! empty( $inputs['rank_math_xml_sitemap'] ) ? 1 : 0;
return $inputs;
}
add_filter( 'rocket_inputs_sanitize', 'rank_math_rocket_sitemap_option_sanitize' );
/**
* Add SEO sitemap URL to the sitemaps to preload
*
* @since 3.2.3
*
* @param array $sitemaps Sitemaps to preload.
* @return array Updated Sitemaps to preload
*/
function rank_math_rocket_sitemap( $sitemaps ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
if ( get_rocket_option( 'rank_math_xml_sitemap', false ) ) {
$sitemaps[] = \RankMath\Sitemap\Router::get_base_url( 'sitemap_index.xml' );
}
return $sitemaps;
}
add_filter( 'rocket_sitemap_preload_list', 'rank_math_rocket_sitemap' );

View File

@@ -0,0 +1,98 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( function_exists( 'seopress_get_toggle_xml_sitemap_option' ) && 1 === (int) seopress_get_toggle_xml_sitemap_option() ) :
/**
* Improvement with SEOPress: auto-detect the XML sitemaps for the preload option
*
* @since 3.3.6
* @author Benjamin Denis
* @source ./yoast-seo.php (Remy Perona)
*/
if ( function_exists( 'seopress_xml_sitemap_general_enable_option' ) && 1 === (int) seopress_xml_sitemap_general_enable_option() ) {
/**
* Add SEOPress sitemap option to WP Rocket default options
*
* @since 3.3.6
* @author Benjamin Denis
* @source ./yoast-seo.php (Remy Perona)
*
* @param array $options WP Rocket options array.
* @return array Updated WP Rocket options array
*/
function rocket_add_seopress_sitemap_option( $options ) {
$options['seopress_xml_sitemap'] = 0;
return $options;
}
add_filter( 'rocket_first_install_options', 'rocket_add_seopress_sitemap_option' );
/**
* Sanitize SEOPress sitemap option value
*
* @since 3.3.6
* @author Benjamin Denis
* @source ./yoast-seo.php (Remy Perona)
*
* @param array $inputs WP Rocket inputs array.
* @return array Sanitized WP Rocket inputs array
*/
function rocket_seopress_sitemap_option_sanitize( $inputs ) {
$inputs['seopress_xml_sitemap'] = ! empty( $inputs['seopress_xml_sitemap'] ) ? 1 : 0;
return $inputs;
}
add_filter( 'rocket_inputs_sanitize', 'rocket_seopress_sitemap_option_sanitize' );
/**
* Add SEOPress sitemap URL to the sitemaps to preload
*
* @since 3.3.6
* @author Benjamin Denis
* @source ./yoast-seo.php (Remy Perona)
*
* @param array $sitemaps Sitemaps to preload.
* @return array Updated Sitemaps to preload
*/
function rocket_add_seopress_sitemap( $sitemaps ) {
if ( get_rocket_option( 'seopress_xml_sitemap', false ) ) {
$sitemaps[] = get_home_url() . '/sitemaps.xml';
}
return $sitemaps;
}
add_filter( 'rocket_sitemap_preload_list', 'rocket_add_seopress_sitemap' );
/**
* Add SEOPress option to WP Rocket settings
*
* @since 3.3.6
* @author Benjamin Denis
* @source ./yoast-seo.php (Remy Perona)
*
* @param array $options WP Rocket settings array.
* @return array Updated WP Rocket settings array
*/
function rocket_sitemap_preload_seopress_option( $options ) {
$options['seopress_xml_sitemap'] = [
'type' => 'checkbox',
'container_class' => [
'wpr-field--children',
],
'label' => __( 'SEOPress XML sitemap', 'rocket' ),
// translators: %s = Name of the plugin.
'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'SEOPress' ),
'parent' => 'sitemap_preload',
'section' => 'preload_section',
'page' => 'preload',
'default' => 0,
'sanitize_callback' => 'sanitize_checkbox',
];
return $options;
}
add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_preload_seopress_option' );
}
endif;

View File

@@ -0,0 +1,153 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* This file is loaded at plugins_loaded, priority 10.
* This function is available at plugins_loaded, priority 5:
*/
if ( ! function_exists( 'the_seo_framework' ) ) {
return;
}
rocket_add_tsf_compat();
/**
* Runs detection and adds extra compatibility for The SEO Framework plugin.
*
* @since 3.2.1
* @since TODO Removed "conflicting sitemap detection" (detect_sitemap_plugin) call.
* TSF always tries to output it now while trying to give WP Rewrite priority for display.
* @author Sybre Waaijer
*/
function rocket_add_tsf_compat() {
$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() ) {
rocket_add_tsf_sitemap_compat();
}
}
/**
* Adds compatibility for the sitemap functionality in The SEO Framework plugin.
*
* @since 3.2.1
* @author Sybre Waaijer
*/
function rocket_add_tsf_sitemap_compat() {
add_filter( 'rocket_first_install_options', 'rocket_add_tsf_seo_sitemap_option' );
add_filter( 'rocket_inputs_sanitize', 'rocket_tsf_seo_sitemap_option_sanitize' );
add_filter( 'rocket_sitemap_preload_list', 'rocket_add_tsf_sitemap_to_preload' );
add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_add_tsf_sitemap_to_preload_option' );
}
/**
* Adds a sitemap option in WP Rocket for The SEO Framework.
*
* @since 3.2.1
* @author Sybre Waaijer
* @source ./yoast-seo.php (Remy Perona)
*
* @param array $options WP Rocket options array.
* @return array Updated WP Rocket options array
*/
function rocket_add_tsf_seo_sitemap_option( $options ) {
$options['tsf_xml_sitemap'] = 0;
return $options;
}
/**
* Sanitizes the added sitemap option for The SEO Framework.
*
* @since 3.2.1
* @author Sybre Waaijer
* @source ./yoast-seo.php (Remy Perona)
*
* @param array $inputs WP Rocket inputs array.
* @return array Sanitized WP Rocket inputs array
*/
function rocket_tsf_seo_sitemap_option_sanitize( $inputs ) {
$inputs['tsf_xml_sitemap'] = ! empty( $inputs['tsf_xml_sitemap'] ) ? 1 : 0;
return $inputs;
}
/**
* Adds TSF sitemap URLs to preload.
*
* @since 3.2.1
* @since TODO Added compatibility support for The SEO Framework v4.0+
* @author Sybre Waaijer
* @source ./yoast-seo.php (Remy Perona)
*
* @param array $sitemaps Sitemaps to preload.
* @return array Updated Sitemaps to preload
*/
function rocket_add_tsf_sitemap_to_preload( $sitemaps ) {
if ( get_rocket_option( 'tsf_xml_sitemap', false ) ) {
// The autoloader in TSF doesn't check for file_exists(). So, use version compare instead to prevent fatal errors.
if ( version_compare( THE_SEO_FRAMEWORK_VERSION, '4.0', '>=' ) ) {
// TSF 4.0+. Expect the class to exist indefinitely.
$sitemap_bridge = The_SEO_Framework\Bridges\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;
}
/**
* Add The SEO Framework SEO option to WP Rocket settings
*
* @since 3.2.1
* @author Sybre Waaijer
* @source ./yoast-seo.php (Remy Perona)
*
* @param array $options WP Rocket settings array.
* @return array Updated WP Rocket settings array
*/
function rocket_sitemap_add_tsf_sitemap_to_preload_option( $options ) {
$options['tsf_xml_sitemap'] = [
'type' => 'checkbox',
'container_class' => [
'wpr-field--children',
],
'label' => __( 'The SEO Framework XML sitemap', 'rocket' ),
// translators: %s = Name of the plugin.
'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'The SEO Framework' ),
'parent' => 'sitemap_preload',
'section' => 'preload_section',
'page' => 'preload',
'default' => 0,
'sanitize_callback' => 'sanitize_checkbox',
];
return $options;
}

View File

@@ -0,0 +1,99 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( defined( 'WPSEO_VERSION' ) && class_exists( 'WPSEO_Sitemaps_Router' ) ) :
$yoast_seo_xml = get_option( 'wpseo_xml' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
if ( version_compare( 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
}
/**
* Improvement with Yoast SEO: auto-detect the XML sitemaps for the preload option
*
* @since 2.8
* @author Remy Perona
*/
if ( true === $yoast_seo_xml['enablexmlsitemap'] ) {
/**
* Add Yoast SEO sitemap option to WP Rocket default options
*
* @since 2.8
* @author Remy Perona
*
* @param array $options WP Rocket options array.
* @return array Updated WP Rocket options array
*/
function rocket_add_yoast_seo_sitemap_option( $options ) {
$options['yoast_xml_sitemap'] = 0;
return $options;
}
add_filter( 'rocket_first_install_options', 'rocket_add_yoast_seo_sitemap_option' );
/**
* Sanitize Yoast SEO sitemap option value
*
* @since 2.8
* @author Remy Perona
*
* @param array $inputs WP Rocket inputs array.
* @return array Sanitized WP Rocket inputs array
*/
function rocket_yoast_seo_sitemap_option_sanitize( $inputs ) {
$inputs['yoast_xml_sitemap'] = ! empty( $inputs['yoast_xml_sitemap'] ) ? 1 : 0;
return $inputs;
}
add_filter( 'rocket_inputs_sanitize', 'rocket_yoast_seo_sitemap_option_sanitize' );
/**
* Add Yoast SEO sitemap URL to the sitemaps to preload
*
* @since 2.8
* @author Remy Perona
*
* @param array $sitemaps Sitemaps to preload.
* @return array Updated Sitemaps to preload
*/
function rocket_add_yoast_seo_sitemap( $sitemaps ) {
if ( get_rocket_option( 'yoast_xml_sitemap', false ) ) {
$sitemaps[] = WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' );
}
return $sitemaps;
}
add_filter( 'rocket_sitemap_preload_list', 'rocket_add_yoast_seo_sitemap' );
/**
* Add Yoast SEO option to WP Rocket settings
*
* @since 2.8
* @author Remy Perona
*
* @param array $options WP Rocket settings array.
* @return array Updated WP Rocket settings array
*/
function rocket_sitemap_preload_yoast_seo_option( $options ) {
$options['yoast_xml_sitemap'] = [
'type' => 'checkbox',
'container_class' => [
'wpr-field--children',
],
'label' => __( 'Yoast SEO XML sitemap', 'rocket' ),
// translators: %s = Name of the plugin.
'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Yoast SEO' ),
'parent' => 'sitemap_preload',
'section' => 'preload_section',
'page' => 'preload',
'default' => 0,
'sanitize_callback' => 'sanitize_checkbox',
];
return $options;
}
add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_preload_yoast_seo_option' );
}
endif;

View File

@@ -0,0 +1,13 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Conflict with LayerSlider: don't add width and height attributes on all images
*
* @since 2.1
*/
function rocket_deactivate_specify_image_dimensions_with_layerslider() {
remove_filter( 'rocket_buffer', 'rocket_specify_image_dimensions' );
}
add_action( 'layerslider_ready', 'rocket_deactivate_specify_image_dimensions_with_layerslider' );

View File

@@ -0,0 +1,17 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Conflict with Meta Slider (Nivo Slider): don't apply LazyLoad on all images
*
* @since 2.4
*
* @param array $slide Slide attributes.
* @return array Updated slide attributes
*/
function rocket_deactivate_lazyload_on_metaslider( $slide ) {
$slide['data-no-lazy'] = 1;
return $slide;
}
add_filter( 'metaslider_nivo_slider_image_attributes', 'rocket_deactivate_lazyload_on_metaslider' );

View File

@@ -0,0 +1,31 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Conflict with Soliloquy: don't apply LazyLoad on all images
*
* @since 2.4.2
*
* @param string $attr Image attributes.
* @return string Updated attributes
*/
function rocket_deactivate_lazyload_on_soliloquy( $attr ) {
return $attr . ' data-no-lazy="1" ';
}
add_filter( 'soliloquy_output_image_attr', 'rocket_deactivate_lazyload_on_soliloquy', PHP_INT_MAX );
/**
* Conflict with Soliloquy: don't apply LazyLoad on all images
*
* @since 2.4.2
*
* @param string $images Image HTML code.
* @return string Updated image HTML code
*/
function rocket_deactivate_lazyload_on_soliloquy_indexable_images( $images ) {
$images = str_replace( '<img', '<img data-no-lazy="1" ', $images );
return $images;
}
add_filter( 'soliloquy_indexable_images', 'rocket_deactivate_lazyload_on_soliloquy_indexable_images', PHP_INT_MAX );

View File

@@ -0,0 +1,53 @@
<?php
/**
* Compatibility with SumoMe
*
* Prevents conflict with SumoMe and the WP Rocket UI by removing SumoMe
* styles and scripts on WP Rocket admin pages.
*
* @link https://wordpress.org/plugins/sumome/
* @since 3.0.4
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'WP_Plugin_SumoMe' ) ) {
/**
* Dequeue SumoMe styles
*
* @since 3.0.4
* @author Arun Basil Lal
*/
function rocket_dequeue_sumo_me_css() {
// Retun on all pages but WP Rocket settings page.
$screen = get_current_screen();
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
wp_dequeue_style( 'sumome-admin-styles' );
wp_dequeue_style( 'sumome-admin-media' );
}
add_action( 'admin_enqueue_scripts', 'rocket_dequeue_sumo_me_css', PHP_INT_MAX );
/**
* Dequeue SumoMe inline script
*
* @since 3.0.4
* @author Arun Basil Lal
*/
function rocket_dequeue_sumo_me_js() {
// Retun on all pages but WP Rocket settings page.
$screen = get_current_screen();
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
global $wp_plugin_sumome;
remove_action( 'admin_footer', [ $wp_plugin_sumome, 'append_admin_script_code' ] );
}
add_action( 'admin_head', 'rocket_dequeue_sumo_me_js' );
}

View File

@@ -0,0 +1,13 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Conflict with Thrive Leads: override the DONOTCACHEPAGE behavior because this plugin add this constant!
*
* @since 2.5
*/
function rocket_override_donotcachepage_on_thrive_leads() {
return defined( 'TVE_LEADS_VERSION' ) && TVE_LEADS_VERSION > 0;
}
add_filter( 'rocket_override_donotcachepage', 'rocket_override_donotcachepage_on_thrive_leads' );

View File

@@ -0,0 +1,75 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'VarnishPurger' ) ) :
add_action( 'admin_init', 'rocket_clear_cache_after_varnish_http_purge' );
/**
* Clear WP Rocket cache after purged the Varnish cache via Varnish HTTP Purge plugin
*
* @since 2.5.5
*
* @return void
*/
function rocket_clear_cache_after_varnish_http_purge() {
if ( isset( $_GET['vhp_flush_all'] ) && current_user_can( 'manage_options' ) && check_admin_referer( 'varnish-http-purge' ) ) {
// Clear all caching files.
rocket_clean_domain();
// Preload cache.
run_rocket_bot();
run_rocket_sitemap_preload();
}
}
endif;
add_action( 'after_rocket_clean_domain', 'rocket_clean_varnish_http_purge' );
/**
* Call the cache server to purge the cache with Varnish HTTP Purge.
*
* @since 2.5.5
*
* @return void
*/
function rocket_clean_varnish_http_purge() {
if ( class_exists( 'VarnishPurger' ) ) {
$url = home_url( '/?vhp-regex' );
$p = wp_parse_url( $url );
$path = '';
$pregex = '.*';
// Build a varniship.
if ( defined( 'VHP_VARNISH_IP' ) && VHP_VARNISH_IP ) {
$varniship = VHP_VARNISH_IP;
} else {
$varniship = get_option( 'vhp_varnish_ip' );
}
if ( isset( $p['path'] ) ) {
$path = $p['path'];
}
$schema = apply_filters( 'varnish_http_purge_schema', 'http://' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
// If we made varniship, let it sail.
if ( ! empty( $varniship ) ) {
$purgeme = $schema . $varniship . $path . $pregex;
} else {
$purgeme = $schema . $p['host'] . $path . $pregex;
}
wp_remote_request(
$purgeme,
[
'method' => 'PURGE',
'blocking' => false,
'headers' => [
'host' => $p['host'],
'X-Purge-Method' => 'regex',
],
]
);
do_action( 'after_purge_url', $url, $purgeme ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}
}

View File

@@ -0,0 +1,38 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( is_admin() && function_exists( 'as3cf_assets_init' ) ) :
add_action( 'aws_init', 'rocket_as3cf_assets_compatibility', 13 );
add_action( 'update_option_as3cf_assets', 'rocket_maybe_deactivate_cdn', 10, 2 );
endif;
/**
* Compatibility with WP Offload S3 assets addon.
*
* @since 2.10.7
* @author Remy Perona
*/
function rocket_as3cf_assets_compatibility() {
global $as3cf_assets;
if ( isset( $as3cf_assets ) && $as3cf_assets->is_plugin_setup() && 1 === (int) $as3cf_assets->get_setting( 'enable-addon' ) ) {
// Disable WP Rocket CDN option.
add_filter( 'rocket_readonly_cdn_option', '__return_true' );
}
}
/**
* Deactivate WP Rocket CDN if WP Offload S3 assets addon copy & serve is active.
*
* @since 2.10.7
* @author Remy Perona
*
* @param string $old_value Previous assets option value.
* @param string $new_value New assets option value.
*/
function rocket_maybe_deactivate_cdn( $old_value, $new_value ) {
if ( $old_value['enable-addon'] !== $new_value['enable-addon'] && 1 === (int) $new_value['enable-addon'] ) {
update_rocket_option( 'cdn', 0 );
}
}

View File

@@ -0,0 +1,23 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( is_admin() && ( function_exists( 'as3cf_init' ) || function_exists( 'as3cf_pro_init' ) ) ) :
add_action( 'aws_init', 'rocket_as3cf_compatibility', 12 );
endif;
/**
* Compatibility with WP Offload S3.
*
* @since 2.10.7
* @author Remy Perona
*/
function rocket_as3cf_compatibility() {
global $as3cf;
if ( isset( $as3cf ) && $as3cf->is_plugin_setup() && 1 === (int) $as3cf->get_setting( 'serve-from-s3' ) ) {
// Remove images option from WP Rocket CDN dropdown settings.
add_filter( 'rocket_allow_cdn_images', '__return_false' );
}
}

View File

@@ -0,0 +1,19 @@
<?php
defined( 'ABSPATH' ) || exit;
if ( function_exists( 'print_link' ) ) :
/**
* Conflict with WP-Print: don't apply LazyLoad on print pages
*
* @since 2.6.8
*/
function rocket_deactivate_lazyload_on_print_pages() {
global $wp_query;
if ( isset( $wp_query->query_vars['print'] ) ) {
add_filter( 'do_rocket_lazyload', '__return_false' );
}
}
add_action( 'wp', 'rocket_deactivate_lazyload_on_print_pages' );
endif;

View File

@@ -0,0 +1,48 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Add WP REST API path to cache exclusion
*
* @since 2.5.12
*
* @param array $uri URLs to exclude from cache.
* @return array Updated URLs
*/
function rocket_exclude_wp_rest_api( $uri ) {
global $wp_rewrite;
/**
* By default, don't cache the WP REST API.
*
* @since 2.5.12
*
* @param bool false will force to cache the WP REST API
*/
$reject_wp_rest_api = apply_filters( 'rocket_cache_reject_wp_rest_api', true );
if ( ! $reject_wp_rest_api ) {
return $uri;
}
/**
* `(/[^/]+)?` is used instead of `(/.+)?` to match only one level.
* This prevents to match a taxonomy term named `wp-json` (on multisite, the main site's posts and taxonomy archives are prefixed with `blog` => example.com/blog/category/wp-json/).
*/
$prefix = rocket_is_subfolder_install() ? '(/[^/]+)?' : '';
$index = ! empty( $wp_rewrite->index ) ? $wp_rewrite->index : 'index.php';
$index = preg_quote( $index, '/' );
$suffix = rest_get_url_prefix();
$suffix = preg_quote( trim( $suffix, '/' ), '/' );
/**
* Results in:
* - Single site: (/index\.php)?/wp\-json(/.*|$)
* - Multisite: (/[^/]+)?(/index\.php)?/wp\-json(/.*|$)
*/
$uri[] = $prefix . '/(' . $index . '/)?' . $suffix . '(/.*|$)';
return $uri;
}
add_filter( 'rocket_cache_reject_uri', 'rocket_exclude_wp_rest_api' );

View File

@@ -0,0 +1,68 @@
<?php
defined( 'ABSPATH' ) || exit;
$current_theme = wp_get_theme(); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
if ( 'Avada' === $current_theme->get( 'Name' ) ) {
// When Avada theme purge its own cache.
add_action( 'avada_clear_dynamic_css_cache', '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
*/
function rocket_avada_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 );
}
}
add_action( 'update_option_fusion_options', 'rocket_avada_maybe_deactivate_lazyload', 10, 2 );
}
/**
* Disable WP Rocket lazyload field if Avada lazyload is enabled
*
* @since 3.3.4
*
* @return bool
*/
function rocket_avada_maybe_disable_lazyload() {
$avada_options = get_option( 'fusion_options' );
$current_theme = wp_get_theme();
if ( 'Avada' !== $current_theme->get( 'Name' ) ) {
return false;
}
if ( empty( $avada_options['lazy_load'] ) ) {
return false;
}
if ( ! empty( $avada_options['lazy_load'] && 'avada' !== $avada_options['lazy_load'] ) ) {
return false;
}
return true;
}
/**
* Clears WP Rocket's cache after Avada's Fusion Patcher flushes their caches
*
* @since 3.3.5
*
* @return void
*/
function rocket_avada_clear_cache_fusion_patcher() {
rocket_clean_domain();
}
add_action( 'fusion_cache_reset_after', 'rocket_avada_clear_cache_fusion_patcher' );

View File

@@ -0,0 +1,44 @@
<?php
defined( 'ABSPATH' ) || exit;
add_action( 'admin_init', 'rocket_clear_cache_after_studiopress_accelerator' );
/**
* Clear WP Rocket cache after purged the StudioPress Accelerator cache
*
* @since 2.5.5
*
* @return void
*/
function rocket_clear_cache_after_studiopress_accelerator() {
if ( isset( $GLOBALS['sp_accel_nginx_proxy_cache_purge'] ) && is_a( $GLOBALS['sp_accel_nginx_proxy_cache_purge'], 'SP_Accel_Nginx_Proxy_Cache_Purge' ) && isset( $_REQUEST['_wpnonce'] ) ) {
$nonce = $_REQUEST['_wpnonce']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Recommended
if ( wp_verify_nonce( $nonce, 'sp-accel-purge-url' ) && ! empty( $_REQUEST['cache-purge-url'] ) ) {
$submitted_url = sanitize_text_field( wp_unslash( $_REQUEST['cache-purge-url'] ) );
// Clear the URL.
rocket_clean_files( [ $submitted_url ] );
} elseif ( wp_verify_nonce( $nonce, 'sp-accel-purge-theme' ) ) {
// Clear all caching files.
rocket_clean_domain();
// Preload cache.
run_rocket_bot();
run_rocket_sitemap_preload();
}
}
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_studiopress_accelerator' );
/**
* Call the cache server to purge the cache with StudioPress Accelerator.
*
* @since 2.5.5
*
* @return void
*/
function rocket_clean_studiopress_accelerator() {
if ( isset( $GLOBALS['sp_accel_nginx_proxy_cache_purge'] ) && is_a( $GLOBALS['sp_accel_nginx_proxy_cache_purge'], 'SP_Accel_Nginx_Proxy_Cache_Purge' ) ) {
$GLOBALS['sp_accel_nginx_proxy_cache_purge']->cache_flush_theme();
}
}

View File

@@ -0,0 +1,64 @@
<?php
defined( 'ABSPATH' ) || exit;
$current_theme = wp_get_theme(); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
if ( 'uncode' === strtolower( $current_theme->get( 'Name' ) ) || 'uncode' === strtolower( $current_theme->get( 'Template' ) ) ) {
/**
* Excludes Uncode init and ai-uncode JS files from minification/combine
*
* @since 3.1
* @author Remy Perona
*
* @param array $excluded_js Array of JS filepaths to be excluded.
* @return array
*/
function rocket_exclude_js_uncode( $excluded_js ) {
$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/ai-uncode.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/ai-uncode.min.js' );
return $excluded_js;
}
add_filter( 'rocket_exclude_js', 'rocket_exclude_js_uncode' );
/**
* Excludes some Uncode inline scripts from combine JS
*
* @since 3.1
* @author Remy Perona
*
* @param array $inline_js Array of patterns to match for exclusion.
* @return array
*/
function rocket_exclude_inline_js_uncode( $inline_js ) {
$inline_js[] = 'SiteParameters';
$inline_js[] = 'script-';
$inline_js[] = 'initBox';
$inline_js[] = 'initHeader';
$inline_js[] = 'fixMenuHeight';
return $inline_js;
}
add_filter( 'rocket_excluded_inline_js_content', 'rocket_exclude_inline_js_uncode' );
if ( version_compare( $current_theme->get( 'Version' ), '2.1', '<' ) ) {
/**
* Excludes Uncode JS files from defer JS
*
* @since 3.2.5
* @author Remy Perona
*
* @param array $exclude_defer_js Array of JS filepaths to be excluded.
* @return array
*/
function rocket_exclude_defer_js_uncode( $exclude_defer_js ) {
$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' );
return $exclude_defer_js;
}
add_filter( 'rocket_exclude_defer_js', 'rocket_exclude_defer_js_uncode' );
}
}