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.

Built from https://develop.svn.wordpress.org/trunk@41716


git-svn-id: http://core.svn.wordpress.org/trunk@41550 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2017-10-03 18:41:48 +00:00
parent 0410474758
commit a9b8f70682
2 changed files with 32 additions and 24 deletions

View File

@ -265,28 +265,7 @@ function refresh_blog_details( $blog_id = 0 ) {
$blog_id = get_current_blog_id(); $blog_id = get_current_blog_id();
} }
$details = get_site( $blog_id ); clean_blog_cache( $blog_id );
if ( ! $details ) {
// Make sure clean_blog_cache() gets the blog ID
// when the blog has been previously cached as
// non-existent.
$details = (object) array(
'blog_id' => $blog_id,
'domain' => null,
'path' => null
);
}
clean_blog_cache( $details );
/**
* Fires after the blog details cache is cleared.
*
* @since 3.4.0
*
* @param int $blog_id Blog ID.
*/
do_action( 'refresh_blog_details', $blog_id );
} }
/** /**
@ -443,7 +422,7 @@ function update_blog_details( $blog_id, $details = array() ) {
* *
* @global bool $_wp_suspend_cache_invalidation * @global bool $_wp_suspend_cache_invalidation
* *
* @param WP_Site $blog The site object to be cleared from cache. * @param WP_Site|int $blog The site object or ID to be cleared from cache.
*/ */
function clean_blog_cache( $blog ) { function clean_blog_cache( $blog ) {
global $_wp_suspend_cache_invalidation; global $_wp_suspend_cache_invalidation;
@ -452,6 +431,25 @@ function clean_blog_cache( $blog ) {
return; return;
} }
if ( empty( $blog ) ) {
return;
}
$blog_id = $blog;
$blog = get_site( $blog_id );
if ( ! $blog ) {
if ( ! is_numeric( $blog_id ) ) {
return;
}
// Make sure a WP_Site object exists even when the site has been deleted.
$blog = new WP_Site( (object) array(
'blog_id' => $blog_id,
'domain' => null,
'path' => null,
) );
}
$blog_id = $blog->blog_id; $blog_id = $blog->blog_id;
$domain_path_key = md5( $blog->domain . $blog->path ); $domain_path_key = md5( $blog->domain . $blog->path );
@ -476,6 +474,16 @@ function clean_blog_cache( $blog ) {
do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key ); do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key );
wp_cache_set( 'last_changed', microtime(), 'sites' ); wp_cache_set( 'last_changed', microtime(), 'sites' );
/**
* Fires after the blog details cache is cleared.
*
* @since 3.4.0
* @deprecated 4.9.0 Use clean_site_cache
*
* @param int $blog_id Blog ID.
*/
do_action_deprecated( 'refresh_blog_details', array( $blog_id ), '4.9.0', 'clean_site_cache' );
} }
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-alpha-41715'; $wp_version = '4.9-alpha-41716';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.