diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index 8aa702a937..6a14febc3a 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -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(); } diff --git a/src/wp-includes/ms-default-filters.php b/src/wp-includes/ms-default-filters.php index 00b3bda982..3b22b87e1b 100644 --- a/src/wp-includes/ms-default-filters.php +++ b/src/wp-includes/ms-default-filters.php @@ -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' ); diff --git a/tests/phpunit/tests/ms.php b/tests/phpunit/tests/ms.php index 413f33bddc..251299b7cf 100644 --- a/tests/phpunit/tests/ms.php +++ b/tests/phpunit/tests/ms.php @@ -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;