Multisite: Establish clean_blog_cache() as a replacement for refresh_blog_details().

Going forward, `clean_blog_cache()` is recommended to be used instead of `refresh_blog_details()`. It has been adjusted to match the functionality of the latter, with the exception that it always requires a site ID or object to be passed. The `refresh_blog_details` action has been deprecated in favor of the `clean_site_cache` action. The function itself is not formally deprecated at this point, but will likely be in the near future.

Props spacedmonkey.
Fixes #40201.


git-svn-id: https://develop.svn.wordpress.org/trunk@41716 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Felix Arntz
2017-10-03 18:40:32 +00:00
parent 2e051261f3
commit 0c1c78bf09
2 changed files with 89 additions and 23 deletions
+58
View File
@@ -1084,6 +1084,32 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
$this->assertFalse( wp_cache_get( $key, $group ) );
}
/**
* @ticket 40201
* @dataProvider data_get_site_caches
*/
public function test_clean_blog_cache_with_id( $key, $group ) {
$site = get_site( self::$site_ids['make.wordpress.org/'] );
$replacements = array(
'%blog_id%' => $site->blog_id,
'%domain%' => $site->domain,
'%path%' => $site->path,
'%domain_path_key%' => md5( $site->domain . $site->path ),
);
$key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
wp_cache_set( $key, (object) $site->to_array(), $group );
} else {
wp_cache_set( $key, 'something', $group );
}
clean_blog_cache( $site->blog_id );
$this->assertFalse( wp_cache_get( $key, $group ) );
}
/**
* @ticket 40201
*/
@@ -1122,6 +1148,38 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
$this->assertEquals( $old_count, did_action( 'clean_site_cache' ) );
}
/**
* @ticket 40201
*/
public function test_clean_blog_cache_bails_on_empty_input() {
$old_count = did_action( 'clean_site_cache' );
clean_blog_cache( null );
$this->assertEquals( $old_count, did_action( 'clean_site_cache' ) );
}
/**
* @ticket 40201
*/
public function test_clean_blog_cache_bails_on_non_numeric_input() {
$old_count = did_action( 'clean_site_cache' );
clean_blog_cache( 'something' );
$this->assertEquals( $old_count, did_action( 'clean_site_cache' ) );
}
/**
* @ticket 40201
*/
public function test_clean_blog_cache_works_with_deleted_site() {
$site_id = 12345;
wp_cache_set( $site_id, 'something', 'site-details' );
clean_blog_cache( $site_id );
$this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
}
/**
* @ticket 40201
* @dataProvider data_get_site_caches