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 |
---|---|
504 | if ( empty( $new_blog ) ) |
505 | $new_blog = $GLOBALS['blog_id']; |
506 |
|
507 | $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; |
508 |
|
509 | /* If we're switching to the same blog id that we're on, |
510 | * set the right vars, do the associated actions, but skip |
511 | * the extra unnecessary work */ |
512 | if ( $new_blog == $GLOBALS['blog_id'] ) { |
513 | do_action( 'switch_blog', $new_blog, $new_blog ); |
514 | $GLOBALS['switched'] = true; |
515 | return true; |
516 | } |
517 |
|
518 | $wpdb->set_blog_id( $new_blog ); |
519 | $GLOBALS['table_prefix'] = $wpdb->prefix; |
520 | $prev_blog_id = $GLOBALS['blog_id']; |
521 | $GLOBALS['blog_id'] = $new_blog; |
522 |
|
Line | Code |
541 | } |
542 | } |
543 |
|
544 | if ( did_action( 'init' ) ) { |
545 | $wp_roles->reinit(); |
546 | $current_user = wp_get_current_user(); |
547 | $current_user->for_blog( $new_blog ); |
548 | } |
549 |
|
550 | do_action( 'switch_blog', $new_blog, $prev_blog_id ); |
551 | $GLOBALS['switched'] = true; |
552 |
|
553 | return true; |
554 | } |
555 |
|
556 | /** |
557 | * Restore the current blog, after calling switch_to_blog() |
558 | * |
559 | * @see switch_to_blog() |
Line | Code |
564 | function restore_current_blog() { |
565 | global $wpdb, $wp_roles; |
566 |
|
567 | if ( empty( $GLOBALS['_wp_switched_stack'] ) ) |
568 | return false; |
569 |
|
570 | $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); |
571 |
|
572 | if ( $GLOBALS['blog_id'] == $blog ) { |
573 | do_action( 'switch_blog', $blog, $blog ); |
574 | // If we still have items in the switched stack, consider ourselves still 'switched' |
575 | $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
576 | return true; |
577 | } |
578 |
|
579 | $wpdb->set_blog_id( $blog ); |
580 | $prev_blog_id = $GLOBALS['blog_id']; |
581 | $GLOBALS['blog_id'] = $blog; |
582 | $GLOBALS['table_prefix'] = $wpdb->prefix; |
Line | Code |
602 | } |
603 | } |
604 |
|
605 | if ( did_action( 'init' ) ) { |
606 | $wp_roles->reinit(); |
607 | $current_user = wp_get_current_user(); |
608 | $current_user->for_blog( $blog ); |
609 | } |
610 |
|
611 | do_action( 'switch_blog', $blog, $prev_blog_id ); |
612 |
|
613 | // If we still have items in the switched stack, consider ourselves still 'switched' |
614 | $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
615 |
|
616 | return true; |
617 | } |
618 |
|
619 | /** |
620 | * Determines if switch_to_blog() is in effect |