From 83002e564e15c728882b2392134510d16f5d7d61 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Tue, 28 Mar 2017 02:31:13 +0000 Subject: [PATCH] Multisite: Allow falsy properties to be cached in `site-details`. In previous iterations of `WP_Site`, there was concern that not all properties would be available when storing a site's details in cache. When introduced in [37918], an `ms_loaded` check was added to address this concern. Any properties that are still `false` after `ms_loaded` really are `false` and can be cached as such. Props flixos90. Fixes #40247. git-svn-id: https://develop.svn.wordpress.org/trunk@40344 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-site.php | 12 +----------- tests/phpunit/tests/multisite/siteDetails.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) 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;