Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: switch_blog

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 4 times in this file.

Line Code
587      if ( $new_blog == $GLOBALS['blog_id'] ) {
588           /**
589            * Fires when the blog is switched.
590            *
591            * @since MU
592            *
593            * @param int $new_blog New blog ID.
594            * @param int $new_blog Blog ID.
595            */
596           do_action( 'switch_blog', $new_blog, $new_blog );
597           $GLOBALS['switched'] = true;
598           return true;
599      }
600
601      $wpdb->set_blog_id( $new_blog );
602      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
603      $prev_blog_id = $GLOBALS['blog_id'];
604      $GLOBALS['blog_id'] = $new_blog;
605
 
Line Code
625      }
626
627      if ( did_action( 'init' ) ) {
628           $wp_roles->reinit();
629           $current_user = wp_get_current_user();
630           $current_user->for_blog( $new_blog );
631      }
632
633      /** This filter is documented in wp-includes/ms-blogs.php */
634      do_action( 'switch_blog', $new_blog, $prev_blog_id );
635      $GLOBALS['switched'] = true;
636
637      return true;
638 }
639
640 /**
641  * Restore the current blog, after calling switch_to_blog()
642  *
643  * @see switch_to_blog()
 
Line Code
649      global $wpdb, $wp_roles;
650
651      if ( empty( $GLOBALS['_wp_switched_stack'] ) )
652           return false;
653
654      $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
655
656      if ( $GLOBALS['blog_id'] == $blog ) {
657           /** This filter is documented in wp-includes/ms-blogs.php */
658           do_action( 'switch_blog', $blog, $blog );
659           // If we still have items in the switched stack, consider ourselves still 'switched'
660           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
661           return true;
662      }
663
664      $wpdb->set_blog_id( $blog );
665      $prev_blog_id = $GLOBALS['blog_id'];
666      $GLOBALS['blog_id'] = $blog;
667      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
 
Line Code
688      }
689
690      if ( did_action( 'init' ) ) {
691           $wp_roles->reinit();
692           $current_user = wp_get_current_user();
693           $current_user->for_blog( $blog );
694      }
695
696      /** This filter is documented in wp-includes/ms-blogs.php */
697      do_action( 'switch_blog', $blog, $prev_blog_id );
698
699      // If we still have items in the switched stack, consider ourselves still 'switched'
700      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
701
702      return true;
703 }
704
705 /**
706  * Determines if switch_to_blog() is in effect