diff --git a/src/wp-includes/class-wp-site.php b/src/wp-includes/class-wp-site.php index 53529fe946..c16f498e90 100644 --- a/src/wp-includes/class-wp-site.php +++ b/src/wp-includes/class-wp-site.php @@ -333,17 +333,7 @@ final class WP_Site { $details->home = get_option( 'home' ); restore_current_blog(); - $cache_details = true; - foreach ( array( 'blogname', 'siteurl', 'post_count', 'home' ) as $field ) { - if ( false === $details->$field ) { - $cache_details = false; - break; - } - } - - if ( $cache_details ) { - wp_cache_set( $this->blog_id, $details, 'site-details' ); - } + wp_cache_set( $this->blog_id, $details, 'site-details' ); } /** This filter is documented in wp-includes/ms-blogs.php */ diff --git a/tests/phpunit/tests/multisite/siteDetails.php b/tests/phpunit/tests/multisite/siteDetails.php index 0ba80453ec..c58360b54d 100644 --- a/tests/phpunit/tests/multisite/siteDetails.php +++ b/tests/phpunit/tests/multisite/siteDetails.php @@ -125,6 +125,25 @@ class Tests_Multisite_Site_Details extends WP_UnitTestCase { $this->assertNotFalse( $cached_result ); } + + /** + * @ticket 40247 + */ + public function test_site_details_cached_including_false_values() { + $id = self::factory()->blog->create(); + + $site = get_site( $id ); + + // Trigger retrieving site details (post_count is not set on new sites) + $post_count = $site->post_count; + + $cached_details = wp_cache_get( $site->id, 'site-details' ); + + wpmu_delete_blog( $id, true ); + wp_update_network_site_counts(); + + $this->assertNotFalse( $cached_details ); + } } endif;