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
783      if ( $new_blog == $blog_id ) {
784           /**
785            * Fires when the blog is switched.
786            *
787            * @since MU
788            *
789            * @param int $new_blog New blog ID.
790            * @param int $new_blog Blog ID.
791            */
792           do_action( 'switch_blog', $new_blog, $new_blog );
793           $GLOBALS['switched'] = true;
794           return true;
795      }
796
797      $wpdb->set_blog_id( $new_blog );
798      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
799      $prev_blog_id = $blog_id;
800      $GLOBALS['blog_id'] = $new_blog;
801
 
Line Code
822      }
823
824      if ( did_action( 'init' ) ) {
825           $wp_roles = new WP_Roles();
826           $current_user = wp_get_current_user();
827           $current_user->for_blog( $new_blog );
828      }
829
830      /** This filter is documented in wp-includes/ms-blogs.php */
831      do_action( 'switch_blog', $new_blog, $prev_blog_id );
832      $GLOBALS['switched'] = true;
833
834      return true;
835 }
836
837 /**
838  * Restore the current blog, after calling switch_to_blog()
839  *
840  * @see switch_to_blog()
 
Line Code
855      if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
856           return false;
857      }
858
859      $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
860      $blog_id = get_current_blog_id();
861
862      if ( $blog_id == $blog ) {
863           /** This filter is documented in wp-includes/ms-blogs.php */
864           do_action( 'switch_blog', $blog, $blog );
865           // If we still have items in the switched stack, consider ourselves still 'switched'
866           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
867           return true;
868      }
869
870      $wpdb->set_blog_id( $blog );
871      $prev_blog_id = $blog_id;
872      $GLOBALS['blog_id'] = $blog;
873      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
 
Line Code
896      }
897
898      if ( did_action( 'init' ) ) {
899           $wp_roles = new WP_Roles();
900           $current_user = wp_get_current_user();
901           $current_user->for_blog( $blog );
902      }
903
904      /** This filter is documented in wp-includes/ms-blogs.php */
905      do_action( 'switch_blog', $blog, $prev_blog_id );
906
907      // If we still have items in the switched stack, consider ourselves still 'switched'
908      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
909
910      return true;
911 }
912
913 /**
914  * Determines if switch_to_blog() is in effect