Changeset 45794
- Timestamp:
- 08/14/2019 02:28:52 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ms-blogs.php
r45780 r45794 485 485 * @global WP_Object_Cache $wp_object_cache 486 486 * 487 * @param int $new_blog The id of the blog you want to switch to. Default: current blog488 * @param bool $deprecated Deprecated argument489 * @return true Always returns True.490 */ 491 function switch_to_blog( $new_blog , $deprecated = null ) {487 * @param int $new_blog_id The ID of the blog to switch to. Default: current blog. 488 * @param bool $deprecated Not used. 489 * @return true Always returns true. 490 */ 491 function switch_to_blog( $new_blog_id, $deprecated = null ) { 492 492 global $wpdb; 493 493 494 $ blog_id = get_current_blog_id();495 if ( empty( $new_blog ) ) {496 $new_blog = $blog_id;497 } 498 499 $GLOBALS['_wp_switched_stack'][] = $ blog_id;494 $prev_blog_id = get_current_blog_id(); 495 if ( empty( $new_blog_id ) ) { 496 $new_blog_id = $prev_blog_id; 497 } 498 499 $GLOBALS['_wp_switched_stack'][] = $prev_blog_id; 500 500 501 501 /* … … 504 504 * the extra unnecessary work 505 505 */ 506 if ( $new_blog == $blog_id ) {506 if ( $new_blog_id == $prev_blog_id ) { 507 507 /** 508 508 * Fires when the blog is switched. … … 510 510 * @since MU (3.0.0) 511 511 * 512 * @param int $new_blog New blog ID.513 * @param int $ new_blog Blog ID.512 * @param int $new_blog_id New blog ID. 513 * @param int $prev_blog_id Previous blog ID. 514 514 */ 515 do_action( 'switch_blog', $new_blog , $new_blog);515 do_action( 'switch_blog', $new_blog_id, $prev_blog_id ); 516 516 $GLOBALS['switched'] = true; 517 517 return true; 518 518 } 519 519 520 $wpdb->set_blog_id( $new_blog );520 $wpdb->set_blog_id( $new_blog_id ); 521 521 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); 522 $prev_blog_id = $blog_id; 523 $GLOBALS['blog_id'] = $new_blog; 522 $GLOBALS['blog_id'] = $new_blog_id; 524 523 525 524 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 526 wp_cache_switch_to_blog( $new_blog );525 wp_cache_switch_to_blog( $new_blog_id ); 527 526 } else { 528 527 global $wp_object_cache; … … 546 545 547 546 /** This filter is documented in wp-includes/ms-blogs.php */ 548 do_action( 'switch_blog', $new_blog , $prev_blog_id );547 do_action( 'switch_blog', $new_blog_id, $prev_blog_id ); 549 548 $GLOBALS['switched'] = true; 550 549 … … 553 552 554 553 /** 555 * Restore the current blog, after calling switch_to_blog() 554 * Restore the current blog, after calling switch_to_blog(). 556 555 * 557 556 * @see switch_to_blog() … … 565 564 * @global WP_Object_Cache $wp_object_cache 566 565 * 567 * @return bool True on success, false if we're already on the current blog 566 * @return bool True on success, false if we're already on the current blog. 568 567 */ 569 568 function restore_current_blog() { … … 574 573 } 575 574 576 $ blog= array_pop( $GLOBALS['_wp_switched_stack'] );577 $ blog_id = get_current_blog_id();578 579 if ( $ blog_id == $blog) {575 $new_blog_id = array_pop( $GLOBALS['_wp_switched_stack'] ); 576 $prev_blog_id = get_current_blog_id(); 577 578 if ( $new_blog_id == $prev_blog_id ) { 580 579 /** This filter is documented in wp-includes/ms-blogs.php */ 581 do_action( 'switch_blog', $ blog, $blog);580 do_action( 'switch_blog', $new_blog_id, $prev_blog_id ); 582 581 // If we still have items in the switched stack, consider ourselves still 'switched' 583 582 $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); … … 585 584 } 586 585 587 $wpdb->set_blog_id( $blog ); 588 $prev_blog_id = $blog_id; 589 $GLOBALS['blog_id'] = $blog; 586 $wpdb->set_blog_id( $new_blog_id ); 587 $GLOBALS['blog_id'] = $new_blog_id; 590 588 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); 591 589 592 590 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 593 wp_cache_switch_to_blog( $ blog);591 wp_cache_switch_to_blog( $new_blog_id ); 594 592 } else { 595 593 global $wp_object_cache; … … 614 612 615 613 /** This filter is documented in wp-includes/ms-blogs.php */ 616 do_action( 'switch_blog', $ blog, $prev_blog_id );614 do_action( 'switch_blog', $new_blog_id, $prev_blog_id ); 617 615 618 616 // If we still have items in the switched stack, consider ourselves still 'switched'
Note: See TracChangeset
for help on using the changeset viewer.