WP hooks navigation: Home/browse • Actions index • Filters index
To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).
The best way to understand what a hook does is to look at where it occurs in the source code.
do_action( "hook_name" )apply_filters( "hook_name", "what_to_filter" ).Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.
This hook occurs 4 times in this file.
| Line | Code |
|---|---|
| 518 | * |
| 519 | * @since MU (3.0.0) |
| 520 | * @since 5.4.0 The `$context` parameter was added. |
| 521 | * |
| 522 | * @param int $new_blog_id New blog ID. |
| 523 | * @param int $prev_blog_id Previous blog ID. |
| 524 | * @param string $context Additional context. Accepts 'switch' when called from switch_to_blog() |
| 525 | * or 'restore' when called from restore_current_blog(). |
| 526 | */ |
| 527 | do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' ); |
| 528 | |
| 529 | $GLOBALS['switched'] = true; |
| 530 | |
| 531 | return true; |
| 532 | } |
| 533 | |
| 534 | $wpdb->set_blog_id( $new_blog_id ); |
| 535 | $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
| 536 | $GLOBALS['blog_id'] = $new_blog_id; |
| Line | Code |
| 554 | } else { |
| 555 | wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) ); |
| 556 | } |
| 557 | |
| 558 | wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /** This filter is documented in wp-includes/ms-blogs.php */ |
| 563 | do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' ); |
| 564 | |
| 565 | $GLOBALS['switched'] = true; |
| 566 | |
| 567 | return true; |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Restore the current blog, after calling switch_to_blog(). |
| 572 | * |
| Line | Code |
| 588 | if ( empty( $GLOBALS['_wp_switched_stack'] ) ) { |
| 589 | return false; |
| 590 | } |
| 591 | |
| 592 | $new_blog_id = array_pop( $GLOBALS['_wp_switched_stack'] ); |
| 593 | $prev_blog_id = get_current_blog_id(); |
| 594 | |
| 595 | if ( $new_blog_id == $prev_blog_id ) { |
| 596 | /** This filter is documented in wp-includes/ms-blogs.php */ |
| 597 | do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' ); |
| 598 | |
| 599 | // If we still have items in the switched stack, consider ourselves still 'switched'. |
| 600 | $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
| 601 | |
| 602 | return true; |
| 603 | } |
| 604 | |
| 605 | $wpdb->set_blog_id( $new_blog_id ); |
| 606 | $GLOBALS['blog_id'] = $new_blog_id; |
| Line | Code |
| 625 | } else { |
| 626 | wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) ); |
| 627 | } |
| 628 | |
| 629 | wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /** This filter is documented in wp-includes/ms-blogs.php */ |
| 634 | do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' ); |
| 635 | |
| 636 | // If we still have items in the switched stack, consider ourselves still 'switched'. |
| 637 | $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
| 638 | |
| 639 | return true; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Switches the initialized roles and current user capabilities to another site. |