Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WPML clearing all languages cache #6263

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/3rd-party/hosting/pagely.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ function rocket_clean_pagely() {
$purger->purgeAll();
}
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_pagely' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_pagely' );
2 changes: 1 addition & 1 deletion inc/3rd-party/hosting/siteground.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function rocket_sg_clear_cache() {

if ( rocket_is_supercacher_active() ) {
add_action( 'admin_post_sg-cachepress-purge', 'rocket_sg_clear_cache', 0 );
add_action( 'after_rocket_clean_domain', 'rocket_clean_supercacher' );
add_action( 'rocket_after_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 );
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/plugins/i18n/polylang.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function rocket_force_clean_domain_on_polylang() {
rocket_clean_cache_dir();
}
}
add_action( 'after_rocket_clean_domain', 'rocket_force_clean_domain_on_polylang' );
add_action( 'rocket_after_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'] ) {
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/plugins/nginx-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function rocket_clean_nginx_helper_cache() {

do_action( 'rt_nginx_helper_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_nginx_helper_cache' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_nginx_helper_cache' );

/**
* Clean the NGINX cache after the Used CSS has been generated.
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/plugins/varnish-http-purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function rocket_clear_cache_after_varnish_http_purge() {
}
endif;

add_action( 'after_rocket_clean_domain', 'rocket_clean_varnish_http_purge' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_varnish_http_purge' );
/**
* Call the cache server to purge the cache with Varnish HTTP Purge.
*
Expand Down
2 changes: 1 addition & 1 deletion inc/3rd-party/themes/studiopress.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function rocket_clear_cache_after_studiopress_accelerator() {
}
}

add_action( 'after_rocket_clean_domain', 'rocket_clean_studiopress_accelerator' );
add_action( 'rocket_after_clean_domain', 'rocket_clean_studiopress_accelerator' );
/**
* Call the cache server to purge the cache with StudioPress Accelerator.
*
Expand Down
2 changes: 1 addition & 1 deletion inc/Addon/Cloudflare/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function get_subscribed_events() {
'rocket_varnish_ip' => 'set_varnish_localhost',
'rocket_varnish_purge_request_host' => 'set_varnish_purge_request_host',
'rocket_cron_deactivate_cloudflare_devmode' => 'deactivate_devmode',
'after_rocket_clean_domain' => 'auto_purge',
'rocket_after_clean_domain' => 'auto_purge',
'after_rocket_clean_post' => [ 'auto_purge_by_url', 10, 3 ],
'admin_post_rocket_purge_cloudflare' => 'purge_cache',
'init' => [ 'set_real_ip', 1 ],
Expand Down
2 changes: 1 addition & 1 deletion inc/Addon/Sucuri/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct( Options_Data $options ) {
*/
public static function get_subscribed_events() {
return [
'after_rocket_clean_domain' => 'maybe_clean_firewall_cache',
'rocket_after_clean_domain' => 'maybe_clean_firewall_cache',
'after_rocket_clean_post' => 'maybe_clean_firewall_cache',
'after_rocket_clean_term' => 'maybe_clean_firewall_cache',
'after_rocket_clean_user' => 'maybe_clean_firewall_cache',
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Media/Lazyload/CSS/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static function get_subscribed_events() {
[ 'add_lazy_tag', 24 ],
],
'rocket_buffer' => [ 'maybe_replace_css_images', 1002 ],
'after_rocket_clean_domain' => 'clear_generated_css',
'rocket_after_clean_domain' => 'clear_generated_css',
'wp_enqueue_scripts' => 'insert_lazyload_script',
'rocket_css_image_lazyload_images_load' => [ 'exclude_rocket_lazyload_excluded_src', 10, 2 ],
'rocket_lazyload_css_ignored_urls' => 'remove_svg_from_lazyload_css',
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Preload/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function get_subscribed_events() {
'after_rocket_clean_file' => 'clean_url',
'set_404' => 'delete_url_on_not_found',
'rocket_after_clean_terms' => 'clean_urls',
'after_rocket_clean_domain' => 'clean_full_cache',
'rocket_after_clean_domain' => 'clean_full_cache',
'delete_post' => 'delete_post_preload_cache',
'pre_delete_term' => 'delete_term_preload_cache',
'rocket_preload_format_url' => 'format_preload_url',
Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Hostings/Kinsta.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function get_subscribed_events() {
];

if ( isset( $kinsta_cache ) ) {
$events['after_rocket_clean_domain'] = 'clean_kinsta_cache';
$events['rocket_after_clean_domain'] = 'clean_kinsta_cache';
$events['after_rocket_clean_post'] = 'clean_kinsta_post_cache';
$events['rocket_rucss_after_clearing_usedcss'] = 'clean_kinsta_cache_url';
$events['rocket_rucss_complete_job_status'] = 'clean_kinsta_cache_url';
Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Hostings/Pressable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function get_subscribed_events() {
'do_rocket_generate_caching_files' => [ 'return_false', PHP_INT_MAX ],
'rocket_display_varnish_options_tab' => 'return_false',
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
'after_rocket_clean_domain' => 'purge_pressable_cache',
'rocket_after_clean_domain' => 'purge_pressable_cache',
'rocket_url_to_path' => 'fix_wp_includes_path',
'rocket_set_wp_cache_constant' => 'return_false',
'rocket_generate_advanced_cache_file' => 'return_false',
Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Hostings/Pressidium.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function get_subscribed_events() {
}

if ( class_exists( 'NinukisCaching' ) ) {
$events['after_rocket_clean_domain'] = 'clean_pressidium';
$events['rocket_after_clean_domain'] = 'clean_pressidium';
$events['after_rocket_clean_file'] = [ 'purge_url', 10, 1 ];
$events['after_rocket_clean_post'] = [ 'clean_post', 10, 2 ];
}
Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Hostings/Savvii.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function get_subscribed_events() {
'rocket_display_input_varnish_auto_purge' => 'return_false',
'rocket_cache_mandatory_cookies' => 'return_empty_array',
'init' => 'clear_cache_after_savvii',
'after_rocket_clean_domain' => 'clean_savvii',
'rocket_after_clean_domain' => 'clean_savvii',
];
}

Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Hostings/SpinUpWP.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function get_subscribed_events() {
'do_rocket_generate_caching_files' => 'return_false',
'rocket_display_varnish_options_tab' => 'return_false',
'rocket_cache_mandatory_cookies' => 'return_empty_array',
'after_rocket_clean_domain' => 'purge_site',
'rocket_after_clean_domain' => 'purge_site',
'wp_rocket_loaded' => 'remove_actions',
'after_rocket_clean_file' => 'purge_url',
'rocket_rucss_after_clearing_usedcss' => 'purge_url',
Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Hostings/WPEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function get_subscribed_events() {
'admin_init' => 'run_rocket_bot_after_wpengine',
'rocket_set_wp_cache_constant' => 'return_false',
'do_rocket_generate_caching_files' => 'return_false',
'after_rocket_clean_domain' => 'clean_wpengine',
'rocket_after_clean_domain' => 'clean_wpengine',
'rocket_buffer' => [ 'add_footprint', 50 ],
'rocket_disable_htaccess' => 'return_true',
'rocket_generate_advanced_cache_file' => 'return_false',
Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Hostings/WordPressCom.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function get_subscribed_events() {
'rocket_display_varnish_options_tab' => 'return_false',
'rocket_set_wp_cache_constant' => 'return_false',
'rocket_generate_advanced_cache_file' => 'return_false',
'after_rocket_clean_domain' => 'purge_wpcom_cache',
'rocket_after_clean_domain' => 'purge_wpcom_cache',
];
}

Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Plugins/CDN/Cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function get_subscribed_events() {
'rocket_display_input_do_cloudflare' => 'hide_addon_radio',
'rocket_cloudflare_field_settings' => 'update_addon_field',
'pre_get_rocket_option_do_cloudflare' => 'disable_cloudflare_option',
'after_rocket_clean_domain' => 'purge_cloudflare',
'rocket_after_clean_domain' => 'purge_cloudflare',
'after_rocket_clean_files' => 'purge_cloudflare_partial',
'rocket_rucss_complete_job_status' => 'purge_cloudflare_after_usedcss',
'rocket_rucss_after_clearing_usedcss' => 'purge_cloudflare_after_usedcss',
Expand Down
2 changes: 1 addition & 1 deletion inc/ThirdParty/Plugins/I18n/WPML.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function get_subscribed_events() {
$events['rocket_preload_all_to_pending_condition'] = 'clean_only_right_domain';
$events['rocket_preload_sitemap_before_queue'] = 'add_languages_sitemaps';
$events['after_rocket_clean_home'] = 'remove_root_cached_files';
$events['after_rocket_clean_domain'] = 'remove_root_cached_files';
$events['rocket_after_clean_domain'] = 'remove_root_cached_files';
$events['pre_update_option_icl_sitepress_settings'] = [ 'on_change_directory_for_default_language_clean_cache', 10, 2 ];

return $events;
Expand Down
10 changes: 10 additions & 0 deletions inc/functions/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,16 @@ function rocket_clean_domain( $lang = '', $filesystem = null ) {
do_action( 'after_rocket_clean_domain', $root, $lang, $url ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
}

/**
* Fires after all cache files was deleted.
*
* @since 3.15.5
*
* @param string $lang The current lang to purge.
* @param array|string[] $urls All urls to clean.
*/
do_action( 'rocket_after_clean_domain', $lang, $urls );

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testShouldDoAsExpected($config, $expected) {
foreach ($config['data'] as $cache) {
self::addCache($cache);
}
do_action('after_rocket_clean_domain', 'whatever','whatever', []);
do_action('rocket_after_clean_domain', 'whatever',[]);

foreach ($expected['data'] as $cache) {
$this->assertSame($expected['exists'], self::cacheFound($cache));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function testShouldReturnAsExpected($config, $expected) {
} else {
$this->cache_purge->shouldReceive('purge_complete_caches')->never();
}
do_action('after_rocket_clean_domain');
do_action('rocket_after_clean_domain');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Test_PurgeSite extends TestCase {
public function testShouldCallSpinUpPurgeSite( ) {
Functions\expect( 'spinupwp_purge_site' )->once();

do_action( 'after_rocket_clean_domain' );
do_action( 'rocket_after_clean_domain' );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function set_up() {
}

public function testShouldCleanWPEngine() {
do_action( 'after_rocket_clean_domain' );
do_action( 'rocket_after_clean_domain' );

$this->assertEquals( 1, WpeCommon::getNumberTimesPurgeMemcachedCalled() );
$this->assertEquals( 1, WpeCommon::getNumberTimesVarnishCacheCalled() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Test_PurgeWpCache extends TestCase {
public function testShouldPurgeWpCache( ) {
wp_cache_set( 'homepage_cache', 'Homepage content' );

do_action( 'after_rocket_clean_domain' );
do_action( 'rocket_after_clean_domain' );

$this->assertFalse( wp_cache_get( 'homepage_cache' ) );
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/inc/functions/rocketCleanDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public function testShouldCleanSingleDomain( $i18n, $expected, $config ) {
Actions\expectDone( 'after_rocket_clean_domain' )
->once()
->with( $config['root'], $lang, $url );
Actions\expectDone( 'rocket_after_clean_domain' )
->once()
->with( $lang, $expected['rocket_clean_domain_urls'] );

// Run it.
rocket_clean_domain( $lang );
Expand Down
Loading