Changeset 21485 for trunk/wp-includes/ms-blogs.php
- Timestamp:
- 08/09/2012 04:28:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/ms-blogs.php
r21480 r21485 447 447 * 448 448 * @param int $new_blog The id of the blog you want to switch to. Default: current blog 449 * @param bool $ validate Whether to check if $new_blog exists before proceeding449 * @param bool $deprecated Depecreated argument 450 450 * @return bool True on success, False if the validation failed 451 451 */ 452 function switch_to_blog( $new_blog, $validate = false ) { 453 global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache; 454 455 if ( empty($new_blog) ) 456 $new_blog = $blog_id; 457 458 if ( $validate && ! get_blog_details( $new_blog ) ) 459 return false; 460 461 if ( empty($switched_stack) ) 462 $switched_stack = array(); 463 464 $switched_stack[] = $blog_id; 452 function switch_to_blog( $new_blog, $deprecated = null ) { 453 global $wpdb, $wp_roles; 454 455 if ( empty( $new_blog ) ) 456 $new_blog = $GLOBALS['blog_id']; 457 458 $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; 465 459 466 460 /* If we're switching to the same blog id that we're on, 467 461 * set the right vars, do the associated actions, but skip 468 462 * the extra unnecessary work */ 469 if ( $ blog_id == $new_blog) {470 do_action( 'switch_blog', $ blog_id, $blog_id);471 $ switched= true;463 if ( $new_blog == $GLOBALS['blog_id'] ) { 464 do_action( 'switch_blog', $new_blog, $new_blog ); 465 $GLOBALS['_wp_switched'] = true; 472 466 return true; 473 467 } 474 468 475 $wpdb->set_blog_id($new_blog); 476 $table_prefix = $wpdb->prefix; 477 $prev_blog_id = $blog_id; 478 $blog_id = $new_blog; 479 480 if ( is_object( $wp_roles ) ) { 481 $wpdb->suppress_errors(); 482 if ( method_exists( $wp_roles ,'_init' ) ) 483 $wp_roles->_init(); 484 elseif ( method_exists( $wp_roles, '__construct' ) ) 485 $wp_roles->__construct(); 486 $wpdb->suppress_errors( false ); 487 } 488 489 if ( did_action('init') ) { 469 $wpdb->set_blog_id( $new_blog ); 470 $GLOBALS['table_prefix'] = $wpdb->prefix; 471 $prev_blog_id = $GLOBALS['blog_id']; 472 $GLOBALS['blog_id'] = $new_blog; 473 474 if ( did_action( 'init' ) ) { 475 $wp_roles->reinit(); 490 476 $current_user = wp_get_current_user(); 491 if ( is_object( $current_user ) ) 492 $current_user->for_blog( $blog_id ); 477 $current_user->for_blog( $new_blog ); 493 478 } 494 479 495 480 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 496 wp_cache_switch_to_blog( $ blog_id);481 wp_cache_switch_to_blog( $new_blog ); 497 482 } else { 483 global $wp_object_cache; 484 498 485 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 499 486 $global_groups = $wp_object_cache->global_groups; … … 502 489 503 490 wp_cache_init(); 504 if ( function_exists('wp_cache_add_global_groups') ) { 491 492 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 505 493 if ( is_array( $global_groups ) ) 506 494 wp_cache_add_global_groups( $global_groups ); 507 495 else 508 496 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 509 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ));497 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 510 498 } 511 499 } 512 500 513 do_action('switch_blog', $blog_id, $prev_blog_id); 514 $switched = true; 501 do_action( 'switch_blog', $new_blog, $prev_blog_id ); 502 $GLOBALS['_wp_switched'] = true; 503 515 504 return true; 516 505 } … … 525 514 */ 526 515 function restore_current_blog() { 527 global $ table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;528 529 if ( ! $switched)516 global $wpdb, $wp_roles; 517 518 if ( ! $GLOBALS['_wp_switched'] ) 530 519 return false; 531 520 532 if ( !is_array( $switched_stack ) ) 533 return false; 534 535 $blog = array_pop( $switched_stack ); 536 if ( $blog_id == $blog ) { 521 $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); 522 523 if ( $GLOBALS['blog_id'] == $blog ) { 537 524 do_action( 'switch_blog', $blog, $blog ); 538 / * If we still have items in the switched stack, consider ourselves still 'switched' */539 $ switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0);525 // If we still have items in the switched stack, consider ourselves still 'switched' 526 $GLOBALS['_wp_switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); 540 527 return true; 541 528 } 542 529 543 $wpdb->set_blog_id($blog); 544 $prev_blog_id = $blog_id; 545 $blog_id = $blog; 546 $table_prefix = $wpdb->prefix; 547 548 if ( is_object( $wp_roles ) ) { 549 $wpdb->suppress_errors(); 550 if ( method_exists( $wp_roles ,'_init' ) ) 551 $wp_roles->_init(); 552 elseif ( method_exists( $wp_roles, '__construct' ) ) 553 $wp_roles->__construct(); 554 $wpdb->suppress_errors( false ); 555 } 556 557 if ( did_action('init') ) { 530 $wpdb->set_blog_id( $blog ); 531 $prev_blog_id = $GLOBALS['blog_id']; 532 $GLOBALS['blog_id'] = $blog; 533 $GLOBALS['table_prefix'] = $wpdb->prefix; 534 535 if ( did_action( 'init' ) ) { 536 $wp_roles->reinit(); 558 537 $current_user = wp_get_current_user(); 559 if ( is_object( $current_user ) ) 560 $current_user->for_blog( $blog_id ); 538 $current_user->for_blog( $blog ); 561 539 } 562 540 563 541 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 564 wp_cache_switch_to_blog( $blog _id);542 wp_cache_switch_to_blog( $blog ); 565 543 } else { 544 global $wp_object_cache; 545 566 546 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 567 547 $global_groups = $wp_object_cache->global_groups; … … 570 550 571 551 wp_cache_init(); 572 if ( function_exists('wp_cache_add_global_groups') ) { 552 553 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 573 554 if ( is_array( $global_groups ) ) 574 555 wp_cache_add_global_groups( $global_groups ); 575 556 else 576 557 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 577 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ));558 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 578 559 } 579 560 } 580 561 581 do_action('switch_blog', $blog_id, $prev_blog_id); 582 583 /* If we still have items in the switched stack, consider ourselves still 'switched' */ 584 $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 ); 562 do_action( 'switch_blog', $blog, $prev_blog_id ); 563 564 // If we still have items in the switched stack, consider ourselves still 'switched' 565 $GLOBALS['_wp_switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); 566 585 567 return true; 586 568 }
Note: See TracChangeset
for help on using the changeset viewer.