From 6b2c62eee279b2b03a7f73ac7d1c142857b7e565 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 7 Feb 2019 06:03:32 +0000 Subject: [PATCH] Multisite: After creating a new blog, ensure the blog cache is correctly cleaned up. Props david.binda, spacedmonkey. Fixes #46125. git-svn-id: https://develop.svn.wordpress.org/trunk@44727 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-site.php | 3 +++ tests/phpunit/tests/multisite/site.php | 28 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/wp-includes/ms-site.php b/src/wp-includes/ms-site.php index f26773ac8d..60d1f29035 100644 --- a/src/wp-includes/ms-site.php +++ b/src/wp-includes/ms-site.php @@ -723,6 +723,9 @@ function wp_initialize_site( $site_id, array $args = array() ) { ) ); + // Clean blog cache after populating options. + clean_blog_cache( $site ); + // Populate the site's roles. populate_roles(); $wp_roles = new WP_Roles(); diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index cb3c3d9a05..5397e85dcf 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -2320,6 +2320,34 @@ if ( is_multisite() ) : return $args; } + + /** + * @ticket 46125 + */ + public function test_wpmu_create_blog_cache_cleanup_backward_compatible() { + add_action( 'populate_options', array( $this, 'populate_options_callback' ) ); + + $blog_id = wpmu_create_blog( 'testsite1.example.org', '/test', 'test', 1, array( 'public' => 1 ), 2 ); + + // Should not hit blog_details cache initialised in $this->populate_options_callback tirggered during + // populate_options callback's call of get_blog_details. + $this->assertEquals( 'http://testsite1.example.org/test', get_blog_details( $blog_id )->siteurl ); + $this->assertEquals( 'http://testsite1.example.org/test', get_site( $blog_id )->siteurl ); + + remove_action( 'populate_options', array( $this, 'populate_options_callback' ) ); + } + + /** + * Populate options callback to warm cache for blog-details / site-details cache group + */ + public function populate_options_callback() { + // Cache blog details + $blog_id = get_current_blog_id(); + get_blog_details( $blog_id ); + get_site( $blog_id )->siteurl; + // Set siteurl + update_option( 'siteurl', 'http://testsite1.example.org/test' ); + } } endif;