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
505      if ( $new_blog == $blog_id ) {
506           /**
507            * Fires when the blog is switched.
508            *
509            * @since MU (3.0.0)
510            *
511            * @param int $new_blog New blog ID.
512            * @param int $new_blog Blog ID.
513            */
514           do_action( 'switch_blog', $new_blog, $new_blog );
515           $GLOBALS['switched'] = true;
516           return true;
517      }
518
519      $wpdb->set_blog_id( $new_blog );
520      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
521      $prev_blog_id            = $blog_id;
522      $GLOBALS['blog_id']      = $new_blog;
523
 
Line Code
538                     wp_cache_add_global_groups( $global_groups );
539                } else {
540                     wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
541                }
542                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
543           }
544      }
545
546      /** This filter is documented in wp-includes/ms-blogs.php */
547      do_action( 'switch_blog', $new_blog, $prev_blog_id );
548      $GLOBALS['switched'] = true;
549
550      return true;
551 }
552
553 /**
554  * Restore the current blog, after calling switch_to_blog()
555  *
556  * @see switch_to_blog()
 
Line Code
571      if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
572           return false;
573      }
574
575      $blog    = array_pop( $GLOBALS['_wp_switched_stack'] );
576      $blog_id = get_current_blog_id();
577
578      if ( $blog_id == $blog ) {
579           /** This filter is documented in wp-includes/ms-blogs.php */
580           do_action( 'switch_blog', $blog, $blog );
581           // If we still have items in the switched stack, consider ourselves still 'switched'
582           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
583           return true;
584      }
585
586      $wpdb->set_blog_id( $blog );
587      $prev_blog_id            = $blog_id;
588      $GLOBALS['blog_id']      = $blog;
589      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
 
Line Code
606                     wp_cache_add_global_groups( $global_groups );
607                } else {
608                     wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
609                }
610                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
611           }
612      }
613
614      /** This filter is documented in wp-includes/ms-blogs.php */
615      do_action( 'switch_blog', $blog, $prev_blog_id );
616
617      // If we still have items in the switched stack, consider ourselves still 'switched'
618      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
619
620      return true;
621 }
622
623 /**
624  * Switches the initialized roles and current user capabilities to another site.