Ticket #21459: 21459.diff
File 21459.diff, 8.7 KB (added by , 13 years ago) |
---|
-
wp-includes/ms-blogs.php
325 325 * @since MU 326 326 * 327 327 * @param int $new_blog The id of the blog you want to switch to. Default: current blog 328 * @param bool $ validate Whether to check if $new_blog exists before proceeding328 * @param bool $deprecated Depecreated argument 329 329 * @return bool True on success, False if the validation failed 330 330 */ 331 function switch_to_blog( $new_blog, $ validate = false) {332 global $wpdb, $ table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;331 function switch_to_blog( $new_blog, $deprecated = null ) { 332 global $wpdb, $wp_roles; 333 333 334 if ( empty( $new_blog) )335 $new_blog = $ blog_id;334 if ( empty( $new_blog ) ) 335 $new_blog = $GLOBALS['blog_id']; 336 336 337 if ( $validate && ! get_blog_details( $new_blog ) ) 338 return false; 337 $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; 339 338 340 if ( empty($switched_stack) )341 $switched_stack = array();342 343 $switched_stack[] = $blog_id;344 345 339 /* If we're switching to the same blog id that we're on, 346 340 * set the right vars, do the associated actions, but skip 347 341 * the extra unnecessary work */ 348 if ( $ blog_id == $new_blog) {349 do_action( 'switch_blog', $ blog_id, $blog_id);350 $ switched = true;342 if ( $new_blog == $GLOBALS['blog_id'] ) { 343 do_action( 'switch_blog', $new_blog, $new_blog ); 344 $_wp_switched = true; 351 345 return true; 352 346 } 353 347 354 $wpdb->set_blog_id( $new_blog);355 $ table_prefix= $wpdb->prefix;356 $prev_blog_id = $ blog_id;357 $ blog_id= $new_blog;348 $wpdb->set_blog_id( $new_blog ); 349 $GLOBALS['table_prefix'] = $wpdb->prefix; 350 $prev_blog_id = $GLOBALS['blog_id']; 351 $GLOBALS['blog_id'] = $new_blog; 358 352 359 if ( is_object( $wp_roles ) ) { 360 $wpdb->suppress_errors(); 361 if ( method_exists( $wp_roles ,'_init' ) ) 362 $wp_roles->_init(); 363 elseif ( method_exists( $wp_roles, '__construct' ) ) 364 $wp_roles->__construct(); 365 $wpdb->suppress_errors( false ); 366 } 367 368 if ( did_action('init') ) { 353 if ( did_action( 'init' ) ) { 354 $wp_roles->reinit(); 369 355 $current_user = wp_get_current_user(); 370 if ( is_object( $current_user ) ) 371 $current_user->for_blog( $blog_id ); 356 $current_user->for_blog( $new_blog ); 372 357 } 373 358 374 359 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 375 wp_cache_switch_to_blog( $ blog_id);360 wp_cache_switch_to_blog( $new_blog ); 376 361 } else { 362 global $wp_object_cache; 363 377 364 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 378 365 $global_groups = $wp_object_cache->global_groups; 379 366 else 380 367 $global_groups = false; 381 368 382 369 wp_cache_init(); 383 if ( function_exists('wp_cache_add_global_groups') ) { 370 371 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 384 372 if ( is_array( $global_groups ) ) 385 373 wp_cache_add_global_groups( $global_groups ); 386 374 else 387 375 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 388 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ));376 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 389 377 } 390 378 } 391 379 392 do_action('switch_blog', $blog_id, $prev_blog_id); 393 $switched = true; 380 do_action( 'switch_blog', $new_blog, $prev_blog_id ); 381 $GLOBALS['_wp_switched'] = true; 382 394 383 return true; 395 384 } 396 385 … … 403 392 * @return bool True on success, False if we're already on the current blog 404 393 */ 405 394 function restore_current_blog() { 406 global $ table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;395 global $wpdb, $wp_roles; 407 396 408 if ( ! $switched)397 if ( ! $GLOBALS['_wp_switched'] ) 409 398 return false; 410 399 411 if ( !is_array( $switched_stack ) ) 412 return false; 400 $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); 413 401 414 $blog = array_pop( $switched_stack ); 415 if ( $blog_id == $blog ) { 402 if ( $GLOBALS['blog_id'] == $blog ) { 416 403 do_action( 'switch_blog', $blog, $blog ); 417 / * If we still have items in the switched stack, consider ourselves still 'switched' */418 $ switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0);404 // If we still have items in the switched stack, consider ourselves still 'switched' 405 $GLOBALS['_wp_switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); 419 406 return true; 420 407 } 421 408 422 $wpdb->set_blog_id( $blog);423 $prev_blog_id = $ blog_id;424 $ blog_id= $blog;425 $ table_prefix= $wpdb->prefix;409 $wpdb->set_blog_id( $blog ); 410 $prev_blog_id = $GLOBALS['blog_id']; 411 $GLOBALS['blog_id'] = $blog; 412 $GLOBALS['table_prefix'] = $wpdb->prefix; 426 413 427 if ( is_object( $wp_roles ) ) { 428 $wpdb->suppress_errors(); 429 if ( method_exists( $wp_roles ,'_init' ) ) 430 $wp_roles->_init(); 431 elseif ( method_exists( $wp_roles, '__construct' ) ) 432 $wp_roles->__construct(); 433 $wpdb->suppress_errors( false ); 434 } 435 436 if ( did_action('init') ) { 414 if ( did_action( 'init' ) ) { 415 $wp_roles->reinit(); 437 416 $current_user = wp_get_current_user(); 438 if ( is_object( $current_user ) ) 439 $current_user->for_blog( $blog_id ); 417 $current_user->for_blog( $blog ); 440 418 } 441 419 442 420 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 443 wp_cache_switch_to_blog( $blog _id);421 wp_cache_switch_to_blog( $blog ); 444 422 } else { 423 global $wp_object_cache; 424 445 425 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 446 426 $global_groups = $wp_object_cache->global_groups; 447 427 else 448 428 $global_groups = false; 449 429 450 430 wp_cache_init(); 451 if ( function_exists('wp_cache_add_global_groups') ) { 431 432 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 452 433 if ( is_array( $global_groups ) ) 453 434 wp_cache_add_global_groups( $global_groups ); 454 435 else 455 436 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 456 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ));437 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 457 438 } 458 439 } 459 440 460 do_action( 'switch_blog', $blog_id, $prev_blog_id);441 do_action( 'switch_blog', $blog, $prev_blog_id ); 461 442 462 /* If we still have items in the switched stack, consider ourselves still 'switched' */ 463 $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 ); 443 // If we still have items in the switched stack, consider ourselves still 'switched' 444 $GLOBALS['_wp_switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); 445 464 446 return true; 465 447 } 466 448 -
wp-includes/capabilities.php
108 108 109 109 $this->role_objects = array(); 110 110 $this->role_names = array(); 111 foreach ( (array) $this->roles as $role => $data) {111 foreach ( array_keys( $this->roles ) as $role ) { 112 112 $this->role_objects[$role] = new WP_Role( $role, $this->roles[$role]['capabilities'] ); 113 113 $this->role_names[$role] = $this->roles[$role]['name']; 114 114 } 115 115 } 116 116 117 117 /** 118 * Reinitialize the object 119 * 120 * Recreates the role objects. This is typically called only by switch_to_blog() 121 * after switching wpdb to a new blog ID. 122 * 123 * @since 3.5.0 124 * @access public 125 */ 126 function reinit() { 127 // There is no need to reinit if using the wp_user_roles global. 128 if ( ! $this->use_db ) 129 return; 130 131 global $wpdb, $wp_user_roles; 132 133 // Duplicated from _init() to avoid an extra function call. 134 $this->role_key = $wpdb->prefix . 'user_roles'; 135 $this->roles = get_option( $this->role_key ); 136 $this->role_objects = array(); 137 $this->role_names = array(); 138 foreach ( array_keys( $this->roles ) as $role ) { 139 $this->role_objects[$role] = new WP_Role( $role, $this->roles[$role]['capabilities'] ); 140 $this->role_names[$role] = $this->roles[$role]['name']; 141 } 142 } 143 144 /** 118 145 * Add role name with capabilities to list. 119 146 * 120 147 * Updates the list of roles, if the role doesn't already exist. … … 233 260 * @param string $role Role name to look up. 234 261 * @return bool 235 262 */ 236 function is_role( $role ) 237 { 263 function is_role( $role ) { 238 264 return isset( $this->role_names[$role] ); 239 265 } 240 266 } -
wp-includes/ms-settings.php
126 126 $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php 127 127 $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id ); 128 128 $table_prefix = $wpdb->get_blog_prefix(); 129 $_wp_switched_stack = array(); 130 $_wp_switched = false; 129 131 130 132 // need to init cache again after blog_id is set 131 133 wp_start_object_cache();