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 |
|---|---|
| 486 | if ( empty( $new_blog ) ) |
| 487 | $new_blog = $GLOBALS['blog_id']; |
| 488 | |
| 489 | $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; |
| 490 | |
| 491 | /* If we're switching to the same blog id that we're on, |
| 492 | * set the right vars, do the associated actions, but skip |
| 493 | * the extra unnecessary work */ |
| 494 | if ( $new_blog == $GLOBALS['blog_id'] ) { |
| 495 | do_action( 'switch_blog', $new_blog, $new_blog ); |
| 496 | $GLOBALS['switched'] = true; |
| 497 | return true; |
| 498 | } |
| 499 | |
| 500 | $wpdb->set_blog_id( $new_blog ); |
| 501 | $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
| 502 | $prev_blog_id = $GLOBALS['blog_id']; |
| 503 | $GLOBALS['blog_id'] = $new_blog; |
| 504 | |
| Line | Code |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | if ( did_action( 'init' ) ) { |
| 527 | $wp_roles->reinit(); |
| 528 | $current_user = wp_get_current_user(); |
| 529 | $current_user->for_blog( $new_blog ); |
| 530 | } |
| 531 | |
| 532 | do_action( 'switch_blog', $new_blog, $prev_blog_id ); |
| 533 | $GLOBALS['switched'] = true; |
| 534 | |
| 535 | return true; |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Restore the current blog, after calling switch_to_blog() |
| 540 | * |
| 541 | * @see switch_to_blog() |
| Line | Code |
| 546 | function restore_current_blog() { |
| 547 | global $wpdb, $wp_roles; |
| 548 | |
| 549 | if ( empty( $GLOBALS['_wp_switched_stack'] ) ) |
| 550 | return false; |
| 551 | |
| 552 | $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); |
| 553 | |
| 554 | if ( $GLOBALS['blog_id'] == $blog ) { |
| 555 | do_action( 'switch_blog', $blog, $blog ); |
| 556 | // If we still have items in the switched stack, consider ourselves still 'switched' |
| 557 | $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
| 558 | return true; |
| 559 | } |
| 560 | |
| 561 | $wpdb->set_blog_id( $blog ); |
| 562 | $prev_blog_id = $GLOBALS['blog_id']; |
| 563 | $GLOBALS['blog_id'] = $blog; |
| 564 | $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
| Line | Code |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | if ( did_action( 'init' ) ) { |
| 588 | $wp_roles->reinit(); |
| 589 | $current_user = wp_get_current_user(); |
| 590 | $current_user->for_blog( $blog ); |
| 591 | } |
| 592 | |
| 593 | do_action( 'switch_blog', $blog, $prev_blog_id ); |
| 594 | |
| 595 | // If we still have items in the switched stack, consider ourselves still 'switched' |
| 596 | $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
| 597 | |
| 598 | return true; |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Determines if switch_to_blog() is in effect |