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
This commit is contained in:
parent
308554bd84
commit
83002e564e
@ -333,18 +333,8 @@ 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' );
|
||||
}
|
||||
}
|
||||
|
||||
/** This filter is documented in wp-includes/ms-blogs.php */
|
||||
$details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' );
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user