Ticket #36935: 36935.diff
File 36935.diff, 5.9 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-site.php
200 200 } 201 201 202 202 /** 203 * Isset-er. 204 * 205 * @since 4.6.0 206 * @access public 207 * 208 * @param string $key Property to check if set. 209 * @return bool 210 */ 211 public function __isset( $key ) { 212 switch ( $key ) { 213 case 'blogname': 214 case 'siteurl': 215 case 'post_count': 216 case 'home': 217 return true; 218 } 219 220 return false; 221 } 222 223 /** 224 * Getter. 225 * 226 * @since 4.6.0 227 * @access public 228 * 229 * @param string $key Property to get. 230 * @return mixed 231 */ 232 public function __get( $key ) { 233 switch ( $key ) { 234 case 'blogname': 235 case 'siteurl': 236 case 'post_count': 237 case 'home': 238 $details = $this->get_details(); 239 return $details->$key; 240 } 241 } 242 243 /** 203 244 * Converts an object to array. 204 245 * 205 246 * @since 4.6.0 … … 210 251 public function to_array() { 211 252 return get_object_vars( $this ); 212 253 } 254 255 /** 256 * Retrieve the details for this site. 257 * 258 * This method is used internally to lazy-load the extended properties of a site. 259 * 260 * @since 4.6.0 261 * @access private 262 * 263 * @see WP_Site::__get() 264 * 265 * @return object A raw site object with all details included. 266 */ 267 private function get_details() { 268 $details = wp_cache_get( $this->blog_id, 'blog-details' ); 269 270 if ( $details ) { 271 if ( ! is_object( $details ) ) { 272 if ( $details != -1 ) { 273 // Clear old pre-serialized objects. Cache clients do better with that. 274 wp_cache_delete( $this->blog_id, 'blog-details' ); 275 unset($details); 276 } 277 } else { 278 return $details; 279 } 280 } 281 282 switch_to_blog( $this->blog_id ); 283 // Create a raw copy of the object for backwards compatibility with the filter below. 284 $details = new stdClass(); 285 foreach ( get_object_vars( $this ) as $key => $value ) { 286 $details->$key = $value; 287 } 288 $details->blogname = get_option( 'blogname' ); 289 $details->siteurl = get_option( 'siteurl' ); 290 $details->post_count = get_option( 'post_count' ); 291 $details->home = get_option( 'home' ); 292 restore_current_blog(); 293 294 /** 295 * Filters a blog's details. 296 * 297 * @since MU 298 * 299 * @param object $details The blog details. 300 */ 301 $details = apply_filters( 'blog_details', $details ); 302 303 wp_cache_set( $this->blog_id, $details, 'blog-details' ); 304 305 return $details; 306 } 213 307 } -
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 blog details are lazy-loaded through `WP_Site` and are available as object properties 112 * regardless of the `$get_all` parameter. 111 113 * 112 114 * @global wpdb $wpdb WordPress database abstraction object. 113 115 * … … 135 137 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); 136 138 } 137 139 if ( $blog ) { 138 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); 140 $key = md5( $blog->domain . $blog->path ); 141 wp_cache_set( $key, $blog, 'blog-lookup' ); 139 142 $blog_id = $blog->blog_id; 140 143 } else { 141 144 return false; … … 152 155 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); 153 156 } 154 157 if ( $blog ) { 155 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); 158 $key = md5( $blog->domain ); 159 wp_cache_set( $key, $blog, 'blog-lookup' ); 156 160 $blog_id = $blog->blog_id; 157 161 } else { 158 162 return false; … … 171 175 172 176 $blog_id = (int) $blog_id; 173 177 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 } else { 187 return $details; 188 } 189 } 190 191 // Try the other cache. 192 if ( $get_all ) { 193 $details = wp_cache_get( $blog_id . 'short', 'blog-details' ); 178 if ( isset( $blog ) ) { 179 $blog = new WP_Site( $blog ); 194 180 } else { 195 $details = wp_cache_get( $blog_id, 'blog-details' ); 196 // If short was requested and full cache is set, we can return. 197 if ( $details ) { 198 if ( ! is_object( $details ) ) { 199 if ( $details == -1 ) { 200 return false; 201 } else { 202 // Clear old pre-serialized objects. Cache clients do better with that. 203 wp_cache_delete( $blog_id, 'blog-details' ); 204 unset($details); 205 } 206 } else { 207 return $details; 208 } 209 } 181 $blog = WP_Site::get_instance( $blog_id ); 210 182 } 211 183 212 if ( empty($details) ) { 213 $details = WP_Site::get_instance( $blog_id ); 214 if ( ! $details ) { 215 // Set the full cache. 216 wp_cache_set( $blog_id, -1, 'blog-details' ); 217 return false; 218 } 219 } 220 221 if ( ! $details instanceof WP_Site ) { 222 $details = new WP_Site( $details ); 223 } 224 225 if ( ! $get_all ) { 226 wp_cache_set( $blog_id . $all, $details, 'blog-details' ); 227 return $details; 228 } 229 230 switch_to_blog( $blog_id ); 231 $details->blogname = get_option( 'blogname' ); 232 $details->siteurl = get_option( 'siteurl' ); 233 $details->post_count = get_option( 'post_count' ); 234 $details->home = get_option( 'home' ); 235 restore_current_blog(); 236 237 /** 238 * Filters a blog's details. 239 * 240 * @since MU 241 * 242 * @param object $details The blog details. 243 */ 244 $details = apply_filters( 'blog_details', $details ); 245 246 wp_cache_set( $blog_id . $all, $details, 'blog-details' ); 247 248 $key = md5( $details->domain . $details->path ); 249 wp_cache_set( $key, $details, 'blog-lookup' ); 250 251 return $details; 184 return $blog; 252 185 } 253 186 254 187 /**