In multisite, on the `updated_option` action, if the option name is one of: 'blogname', 'siteurl', 'post_count' - refresh the blog details cache for the current blog id.

Adds unit test.

Props kovshenin.
Fixes #26410.


git-svn-id: https://develop.svn.wordpress.org/trunk@28881 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-06-28 04:06:12 +00:00
parent 54d4f34ad2
commit dca6040b0b
3 changed files with 30 additions and 1 deletions

View File

@ -263,6 +263,19 @@ function refresh_blog_details( $blog_id ) {
do_action( 'refresh_blog_details', $blog_id );
}
/**
* Refresh blog details when an option is updated.
*
* @access private
* @param string $option_name
*/
function _wp_refresh_blog_details_on_updated_option( $option_name ) {
$options = array( 'blogname', 'siteurl', 'post_count' );
if ( in_array( $option_name, $options ) ) {
refresh_blog_details( get_current_blog_id() );
}
}
/**
* Update the details for a blog. Updates the blogs table for a given blog id.
*
@ -903,7 +916,7 @@ function _update_posts_count_on_delete( $post_id ) {
if ( 'publish' !== get_post_field( 'post_status', $post_id ) ) {
return;
}
update_posts_count();
}

View File

@ -70,6 +70,9 @@ add_filter( 'force_filtered_html_on_import', '__return_true' );
remove_filter( 'option_siteurl', '_config_wp_siteurl' );
remove_filter( 'option_home', '_config_wp_home' );
// Some options changes should trigger blog details refresh.
add_action( 'updated_option', '_wp_refresh_blog_details_on_updated_option' );
// If the network upgrade hasn't run yet, assume ms-files.php rewriting is used.
add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );

View File

@ -1397,6 +1397,19 @@ class Tests_MS extends WP_UnitTestCase {
wp_delete_post( $post2 );
$this->assertEquals( 1, get_blog_details()->post_count );
}
/**
* @ticket 26410
*/
function test_blog_details_cache_invalidation() {
update_option( 'blogname', 'foo' );
$details = get_blog_details( get_current_blog_id() );
$this->assertEquals( 'foo', $details->blogname );
update_option( 'blogname', 'bar' );
$details = get_blog_details( get_current_blog_id() );
$this->assertEquals( 'bar', $details->blogname );
}
}
endif;