diff --git a/wp-includes/class-wp-site.php b/wp-includes/class-wp-site.php index 4aac6c1030..d839c59600 100644 --- a/wp-includes/class-wp-site.php +++ b/wp-includes/class-wp-site.php @@ -222,6 +222,7 @@ final class WP_Site { * Getter. * * Allows current multisite naming conventions when getting properties. + * Allows access to extended site properties. * * @since 4.6.0 * @access public @@ -239,6 +240,15 @@ final class WP_Site { return $this->site_id; case 'network_id': return (int) $this->site_id; + case 'blogname': + case 'siteurl': + case 'post_count': + case 'home': + if ( ! did_action( 'ms_loaded' ) ) { + return null; + } + $details = $this->get_details(); + return $details->$key; } return null; @@ -248,6 +258,7 @@ final class WP_Site { * Isset-er. * * Allows current multisite naming conventions when checking for properties. + * Checks for extended site properties. * * @since 4.6.0 * @access public @@ -262,6 +273,14 @@ final class WP_Site { case 'site_id': case 'network_id': return true; + case 'blogname': + case 'siteurl': + case 'post_count': + case 'home': + if ( ! did_action( 'ms_loaded' ) ) { + return false; + } + return true; } return false; @@ -292,4 +311,58 @@ final class WP_Site { $this->$key = $value; } } + + /** + * Retrieve the details for this site. + * + * This method is used internally to lazy-load the extended properties of a site. + * + * @since 4.6.0 + * @access private + * + * @see WP_Site::__get() + * + * @return object A raw site object with all details included. + */ + private function get_details() { + $details = wp_cache_get( $this->blog_id, 'site-details' ); + + if ( false === $details ) { + + switch_to_blog( $this->blog_id ); + // Create a raw copy of the object for backwards compatibility with the filter below. + $details = new stdClass(); + foreach ( get_object_vars( $this ) as $key => $value ) { + $details->$key = $value; + } + $details->blogname = get_option( 'blogname' ); + $details->siteurl = get_option( 'siteurl' ); + $details->post_count = get_option( 'post_count' ); + $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' ); + } + } + + /** + * Filters a site's extended properties. + * + * @since 4.6.0 + * + * @param object $details The site details. + */ + $details = apply_filters( 'site_details', $details ); + + return $details; + } } diff --git a/wp-includes/load.php b/wp-includes/load.php index 80654f1bff..62d033a7c7 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -509,7 +509,7 @@ function wp_start_object_cache() { wp_cache_init(); if ( function_exists( 'wp_cache_add_global_groups' ) ) { - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) ); + wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) ); wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); } } diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 3032f2e031..cb1c89af57 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -455,6 +455,7 @@ function clean_blog_cache( $blog ) { $domain_path_key = md5( $blog->domain . $blog->path ); wp_cache_delete( $blog_id, 'sites' ); + wp_cache_delete( $blog_id, 'site-details' ); wp_cache_delete( $blog_id , 'blog-details' ); wp_cache_delete( $blog_id . 'short' , 'blog-details' ); wp_cache_delete( $domain_path_key, 'blog-lookup' ); @@ -822,7 +823,7 @@ function switch_to_blog( $new_blog, $deprecated = null ) { if ( is_array( $global_groups ) ) { wp_cache_add_global_groups( $global_groups ); } else { - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) ); + wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) ); } wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); } @@ -893,7 +894,7 @@ function restore_current_blog() { if ( is_array( $global_groups ) ) { wp_cache_add_global_groups( $global_groups ); } else { - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) ); + wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) ); } wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 7ca026306c..e8232e19f7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37917'; +$wp_version = '4.6-alpha-37918'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.