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
512      if ( empty( $new_blog ) )
513           $new_blog = $GLOBALS['blog_id'];
514
515      $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id'];
516
517      /* If we're switching to the same blog id that we're on,
518      * set the right vars, do the associated actions, but skip
519      * the extra unnecessary work */
520      if ( $new_blog == $GLOBALS['blog_id'] ) {
521           do_action( 'switch_blog', $new_blog, $new_blog );
522           $GLOBALS['switched'] = true;
523           return true;
524      }
525
526      $wpdb->set_blog_id( $new_blog );
527      $GLOBALS['table_prefix'] = $wpdb->prefix;
528      $prev_blog_id = $GLOBALS['blog_id'];
529      $GLOBALS['blog_id'] = $new_blog;
530
 
Line Code
549           }
550      }
551
552      if ( did_action( 'init' ) ) {
553           $wp_roles->reinit();
554           $current_user = wp_get_current_user();
555           $current_user->for_blog( $new_blog );
556      }
557
558      do_action( 'switch_blog', $new_blog, $prev_blog_id );
559      $GLOBALS['switched'] = true;
560
561      return true;
562 }
563
564 /**
565  * Restore the current blog, after calling switch_to_blog()
566  *
567  * @see switch_to_blog()
 
Line Code
572 function restore_current_blog() {
573      global $wpdb, $wp_roles;
574
575      if ( empty( $GLOBALS['_wp_switched_stack'] ) )
576           return false;
577
578      $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
579
580      if ( $GLOBALS['blog_id'] == $blog ) {
581           do_action( 'switch_blog', $blog, $blog );
582           // If we still have items in the switched stack, consider ourselves still 'switched'
583           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
584           return true;
585      }
586
587      $wpdb->set_blog_id( $blog );
588      $prev_blog_id = $GLOBALS['blog_id'];
589      $GLOBALS['blog_id'] = $blog;
590      $GLOBALS['table_prefix'] = $wpdb->prefix;
 
Line Code
610           }
611      }
612
613      if ( did_action( 'init' ) ) {
614           $wp_roles->reinit();
615           $current_user = wp_get_current_user();
616           $current_user->for_blog( $blog );
617      }
618
619      do_action( 'switch_blog', $blog, $prev_blog_id );
620
621      // If we still have items in the switched stack, consider ourselves still 'switched'
622      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
623
624      return true;
625 }
626
627 /**
628  * Determines if switch_to_blog() is in effect