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