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
810      if ( $new_blog == $blog_id ) {
811           /**
812            * Fires when the blog is switched.
813            *
814            * @since MU
815            *
816            * @param int $new_blog New blog ID.
817            * @param int $new_blog Blog ID.
818            */
819           do_action( 'switch_blog', $new_blog, $new_blog );
820           $GLOBALS['switched'] = true;
821           return true;
822      }
823
824      $wpdb->set_blog_id( $new_blog );
825      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
826      $prev_blog_id = $blog_id;
827      $GLOBALS['blog_id'] = $new_blog;
828
 
Line Code
849      }
850
851      if ( did_action( 'init' ) ) {
852           $wp_roles = new WP_Roles();
853           $current_user = wp_get_current_user();
854           $current_user->for_blog( $new_blog );
855      }
856
857      /** This filter is documented in wp-includes/ms-blogs.php */
858      do_action( 'switch_blog', $new_blog, $prev_blog_id );
859      $GLOBALS['switched'] = true;
860
861      return true;
862 }
863
864 /**
865  * Restore the current blog, after calling switch_to_blog()
866  *
867  * @see switch_to_blog()
 
Line Code
882      if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
883           return false;
884      }
885
886      $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
887      $blog_id = get_current_blog_id();
888
889      if ( $blog_id == $blog ) {
890           /** This filter is documented in wp-includes/ms-blogs.php */
891           do_action( 'switch_blog', $blog, $blog );
892           // If we still have items in the switched stack, consider ourselves still 'switched'
893           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
894           return true;
895      }
896
897      $wpdb->set_blog_id( $blog );
898      $prev_blog_id = $blog_id;
899      $GLOBALS['blog_id'] = $blog;
900      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
 
Line Code
923      }
924
925      if ( did_action( 'init' ) ) {
926           $wp_roles = new WP_Roles();
927           $current_user = wp_get_current_user();
928           $current_user->for_blog( $blog );
929      }
930
931      /** This filter is documented in wp-includes/ms-blogs.php */
932      do_action( 'switch_blog', $blog, $prev_blog_id );
933
934      // If we still have items in the switched stack, consider ourselves still 'switched'
935      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
936
937      return true;
938 }
939
940 /**
941  * Determines if switch_to_blog() is in effect