Ticket #36935: 36935.6.diff
File 36935.6.diff, 12.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-site.php
15 15 * 16 16 * @since 4.5.0 17 17 * 18 * @property int $id 19 * @property int $network_id 18 * @property int $id 19 * @property int $network_id 20 * @property-read string $blogname 21 * @property-read string $siteurl 22 * @property-read string $post_count 23 * @property-read string $home 20 24 */ 21 25 final class WP_Site { 22 26 … … 218 222 * Getter. 219 223 * 220 224 * Allows current multisite naming conventions when getting properties. 225 * Also allows to access extended properties from blog details. 221 226 * 222 227 * @since 4.6.0 223 228 * @access public … … 235 240 return $this->site_id; 236 241 case 'network_id': 237 242 return (int) $this->site_id; 243 case 'blogname': 244 case 'siteurl': 245 case 'post_count': 246 case 'home': 247 $details = $this->get_details(); 248 return $details->$key; 238 249 } 239 250 240 251 return null; … … 244 255 * Isset-er. 245 256 * 246 257 * Allows current multisite naming conventions when checking for properties. 258 * Also successfully checks for extended properties from blog details. 247 259 * 248 260 * @since 4.6.0 249 261 * @access public … … 257 269 case 'blog_id': 258 270 case 'site_id': 259 271 case 'network_id': 272 case 'blogname': 273 case 'siteurl': 274 case 'post_count': 275 case 'home': 260 276 return true; 261 277 } 262 278 … … 288 304 $this->$key = $value; 289 305 } 290 306 } 307 308 /** 309 * Retrieve the details for this site. 310 * 311 * This method is used internally to lazy-load the extended properties of a site. 312 * 313 * @since 4.6.0 314 * @access private 315 * 316 * @see WP_Site::__get() 317 * 318 * @return object A raw site object with all details included. 319 */ 320 private function get_details() { 321 $details = wp_cache_get( $this->blog_id, 'site-details' ); 322 323 if ( false === $details ) { 324 325 switch_to_blog( $this->blog_id ); 326 // Create a raw copy of the object for backwards compatibility with the filter below. 327 $details = new stdClass(); 328 foreach ( get_object_vars( $this ) as $key => $value ) { 329 $details->$key = $value; 330 } 331 $details->blogname = get_option( 'blogname' ); 332 $details->siteurl = get_option( 'siteurl' ); 333 $details->post_count = get_option( 'post_count' ); 334 $details->home = get_option( 'home' ); 335 restore_current_blog(); 336 337 wp_cache_set( $this->blog_id, $details, 'site-details' ); 338 } 339 340 /** 341 * Filters a blog's details. 342 * 343 * @since MU 344 * 345 * @param object $details The blog details. 346 */ 347 $details = apply_filters( 'blog_details', $details ); 348 349 return $details; 350 } 291 351 } -
src/wp-includes/load.php
509 509 wp_cache_init(); 510 510 511 511 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 512 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' ) );512 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' ) ); 513 513 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 514 514 } 515 515 } -
src/wp-includes/ms-blogs.php
108 108 * Retrieve the details for a blog from the blogs table and blog options. 109 109 * 110 110 * @since MU 111 * @since 4.6.0 Extended details are lazy-loaded through `WP_Site` and are available as object properties 112 * regardless of the second parameter which is now deprecated. 111 113 * 114 * @see get_site() 115 * 112 116 * @global wpdb $wpdb WordPress database abstraction object. 113 117 * 114 * @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against. 115 * If not specified the current blog ID is used. 116 * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. 117 * Default is true. 118 * @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against. 119 * If not specified the current blog ID is used. 120 * @param bool $deprecated Deprecated parameter. 118 121 * @return WP_Site|false Blog details on success. False on failure. 119 122 */ 120 function get_blog_details( $fields = null, $ get_all= true ) {123 function get_blog_details( $fields = null, $deprecated = true ) { 121 124 global $wpdb; 122 125 123 126 if ( is_array($fields ) ) { … … 126 129 } elseif ( isset($fields['domain']) && isset($fields['path']) ) { 127 130 $key = md5( $fields['domain'] . $fields['path'] ); 128 131 $blog = wp_cache_get($key, 'blog-lookup'); 129 if ( false !== $blog )130 return $blog;131 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {132 $nowww = substr( $fields['domain'], 4 );133 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );134 } else {135 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );136 }137 132 if ( $blog ) { 138 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');139 133 $blog_id = $blog->blog_id; 140 134 } else { 141 return false; 135 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { 136 $nowww = substr( $fields['domain'], 4 ); 137 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) ); 138 } else { 139 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); 140 } 141 if ( $blog ) { 142 $key = md5( $blog->domain . $blog->path ); 143 wp_cache_set( $key, $blog, 'blog-lookup' ); 144 $blog_id = $blog->blog_id; 145 } else { 146 return false; 147 } 142 148 } 143 149 } elseif ( isset($fields['domain']) && is_subdomain_install() ) { 144 150 $key = md5( $fields['domain'] ); … … 152 158 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); 153 159 } 154 160 if ( $blog ) { 155 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); 161 $key = md5( $blog->domain ); 162 wp_cache_set( $key, $blog, 'blog-lookup' ); 156 163 $blog_id = $blog->blog_id; 157 164 } else { 158 165 return false; … … 171 178 172 179 $blog_id = (int) $blog_id; 173 180 174 $all = $get_all == true ? '' : 'short'; 175 $details = wp_cache_get( $blog_id . $all, 'blog-details' ); 176 177 if ( $details ) { 178 if ( ! is_object( $details ) ) { 179 if ( $details == -1 ) { 180 return false; 181 } else { 182 // Clear old pre-serialized objects. Cache clients do better with that. 183 wp_cache_delete( $blog_id . $all, 'blog-details' ); 184 unset($details); 185 } 186 } elseif ( ! $details->blog_id || ! $details->site_id ) { 187 // Clear objects missing critical properties. 188 wp_cache_delete( $blog_id . $all, 'blog-details' ); 189 unset($details); 190 } else { 191 return $details; 192 } 193 } 194 195 // Try the other cache. 196 if ( $get_all ) { 197 $details = wp_cache_get( $blog_id . 'short', 'blog-details' ); 181 if ( isset( $blog ) ) { 182 $blog = new WP_Site( $blog ); 198 183 } else { 199 $details = wp_cache_get( $blog_id, 'blog-details' ); 200 // If short was requested and full cache is set, we can return. 201 if ( $details ) { 202 if ( ! is_object( $details ) ) { 203 if ( $details == -1 ) { 204 return false; 205 } else { 206 // Clear old pre-serialized objects. Cache clients do better with that. 207 wp_cache_delete( $blog_id, 'blog-details' ); 208 unset($details); 209 } 210 } elseif ( ! $details->blog_id || ! $details->site_id ) { 211 // Clear objects missing critical properties. 212 wp_cache_delete( $blog_id, 'blog-details' ); 213 unset($details); 214 } else { 215 return $details; 216 } 217 } 184 $blog = WP_Site::get_instance( $blog_id ); 218 185 } 219 186 220 if ( empty( $details ) || ! $details->blog_id || ! $details->site_id ) { 221 $details = WP_Site::get_instance( $blog_id ); 222 if ( ! $details ) { 223 // Set the full cache. 224 wp_cache_set( $blog_id, -1, 'blog-details' ); 225 return false; 226 } 227 } 228 229 if ( ! $details instanceof WP_Site ) { 230 $details = new WP_Site( $details ); 231 } 232 233 if ( ! $get_all ) { 234 wp_cache_set( $blog_id . $all, $details, 'blog-details' ); 235 return $details; 236 } 237 238 switch_to_blog( $blog_id ); 239 $details->blogname = get_option( 'blogname' ); 240 $details->siteurl = get_option( 'siteurl' ); 241 $details->post_count = get_option( 'post_count' ); 242 $details->home = get_option( 'home' ); 243 restore_current_blog(); 244 245 /** 246 * Filters a blog's details. 247 * 248 * @since MU 249 * 250 * @param object $details The blog details. 251 */ 252 $details = apply_filters( 'blog_details', $details ); 253 254 wp_cache_set( $blog_id . $all, $details, 'blog-details' ); 255 256 $key = md5( $details->domain . $details->path ); 257 wp_cache_set( $key, $details, 'blog-lookup' ); 258 259 return $details; 187 return $blog; 260 188 } 261 189 262 190 /** … … 316 244 if ( is_object($details) ) 317 245 $details = get_object_vars($details); 318 246 319 $current_details = get_ blog_details($blog_id, false);247 $current_details = get_site( $blog_id ); 320 248 if ( empty($current_details) ) 321 249 return false; 322 250 323 $current_details = get_object_vars($current_details);251 $current_details = $current_details->to_array(); 324 252 325 253 $details = array_merge($current_details, $details); 326 254 $details['last_updated'] = current_time('mysql', true); … … 455 383 $domain_path_key = md5( $blog->domain . $blog->path ); 456 384 457 385 wp_cache_delete( $blog_id, 'sites' ); 458 wp_cache_delete( $blog_id , 'blog-details' ); 459 wp_cache_delete( $blog_id . 'short' , 'blog-details' ); 460 wp_cache_delete( $domain_path_key, 'blog-lookup' ); 386 wp_cache_delete( $blog_id, 'site-details' ); 387 wp_cache_delete( $domain_path_key, 'blog-lookup' ); 461 388 wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); 462 389 wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); 463 390 wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' ); … … 557 484 558 485 foreach ( $sites as $site ) { 559 486 wp_cache_add( $site->blog_id, $site, 'sites' ); 560 wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' );561 487 } 562 488 } 563 489 … … 822 748 if ( is_array( $global_groups ) ) { 823 749 wp_cache_add_global_groups( $global_groups ); 824 750 } else { 825 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' ) );751 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' ) ); 826 752 } 827 753 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 828 754 } … … 893 819 if ( is_array( $global_groups ) ) { 894 820 wp_cache_add_global_groups( $global_groups ); 895 821 } else { 896 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' ) );822 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' ) ); 897 823 } 898 824 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 899 825 }