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
628      if ( $new_blog == $GLOBALS['blog_id'] ) {
629           /**
630            * Fires when the blog is switched.
631            *
632            * @since MU
633            *
634            * @param int $new_blog New blog ID.
635            * @param int $new_blog Blog ID.
636            */
637           do_action( 'switch_blog', $new_blog, $new_blog );
638           $GLOBALS['switched'] = true;
639           return true;
640      }
641
642      $wpdb->set_blog_id( $new_blog );
643      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
644      $prev_blog_id = $GLOBALS['blog_id'];
645      $GLOBALS['blog_id'] = $new_blog;
646
 
Line Code
667      }
668
669      if ( did_action( 'init' ) ) {
670           wp_roles()->reinit();
671           $current_user = wp_get_current_user();
672           $current_user->for_blog( $new_blog );
673      }
674
675      /** This filter is documented in wp-includes/ms-blogs.php */
676      do_action( 'switch_blog', $new_blog, $prev_blog_id );
677      $GLOBALS['switched'] = true;
678
679      return true;
680 }
681
682 /**
683  * Restore the current blog, after calling switch_to_blog()
684  *
685  * @see switch_to_blog()
 
Line Code
698      global $wpdb;
699
700      if ( empty( $GLOBALS['_wp_switched_stack'] ) )
701           return false;
702
703      $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
704
705      if ( $GLOBALS['blog_id'] == $blog ) {
706           /** This filter is documented in wp-includes/ms-blogs.php */
707           do_action( 'switch_blog', $blog, $blog );
708           // If we still have items in the switched stack, consider ourselves still 'switched'
709           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
710           return true;
711      }
712
713      $wpdb->set_blog_id( $blog );
714      $prev_blog_id = $GLOBALS['blog_id'];
715      $GLOBALS['blog_id'] = $blog;
716      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
 
Line Code
738      }
739
740      if ( did_action( 'init' ) ) {
741           wp_roles()->reinit();
742           $current_user = wp_get_current_user();
743           $current_user->for_blog( $blog );
744      }
745
746      /** This filter is documented in wp-includes/ms-blogs.php */
747      do_action( 'switch_blog', $blog, $prev_blog_id );
748
749      // If we still have items in the switched stack, consider ourselves still 'switched'
750      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
751
752      return true;
753 }
754
755 /**
756  * Determines if switch_to_blog() is in effect