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
779      if ( $new_blog == $GLOBALS['blog_id'] ) {
780           /**
781            * Fires when the blog is switched.
782            *
783            * @since MU
784            *
785            * @param int $new_blog New blog ID.
786            * @param int $new_blog Blog ID.
787            */
788           do_action( 'switch_blog', $new_blog, $new_blog );
789           $GLOBALS['switched'] = true;
790           return true;
791      }
792
793      $wpdb->set_blog_id( $new_blog );
794      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
795      $prev_blog_id = $GLOBALS['blog_id'];
796      $GLOBALS['blog_id'] = $new_blog;
797
 
Line Code
818      }
819
820      if ( did_action( 'init' ) ) {
821           wp_roles()->reinit();
822           $current_user = wp_get_current_user();
823           $current_user->for_blog( $new_blog );
824      }
825
826      /** This filter is documented in wp-includes/ms-blogs.php */
827      do_action( 'switch_blog', $new_blog, $prev_blog_id );
828      $GLOBALS['switched'] = true;
829
830      return true;
831 }
832
833 /**
834  * Restore the current blog, after calling switch_to_blog()
835  *
836  * @see switch_to_blog()
 
Line Code
849      global $wpdb;
850
851      if ( empty( $GLOBALS['_wp_switched_stack'] ) )
852           return false;
853
854      $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
855
856      if ( $GLOBALS['blog_id'] == $blog ) {
857           /** This filter is documented in wp-includes/ms-blogs.php */
858           do_action( 'switch_blog', $blog, $blog );
859           // If we still have items in the switched stack, consider ourselves still 'switched'
860           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
861           return true;
862      }
863
864      $wpdb->set_blog_id( $blog );
865      $prev_blog_id = $GLOBALS['blog_id'];
866      $GLOBALS['blog_id'] = $blog;
867      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
 
Line Code
889      }
890
891      if ( did_action( 'init' ) ) {
892           wp_roles()->reinit();
893           $current_user = wp_get_current_user();
894           $current_user->for_blog( $blog );
895      }
896
897      /** This filter is documented in wp-includes/ms-blogs.php */
898      do_action( 'switch_blog', $blog, $prev_blog_id );
899
900      // If we still have items in the switched stack, consider ourselves still 'switched'
901      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
902
903      return true;
904 }
905
906 /**
907  * Determines if switch_to_blog() is in effect