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_id == $prev_blog_id ) {
507           /**
508            * Fires when the blog is switched.
509            *
510            * @since MU (3.0.0)
511            *
512            * @param int $new_blog_id  New blog ID.
513            * @param int $prev_blog_id Previous blog ID.
514            */
515           do_action( 'switch_blog', $new_blog_id, $prev_blog_id );
516           $GLOBALS['switched'] = true;
517           return true;
518      }
519
520      $wpdb->set_blog_id( $new_blog_id );
521      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
522      $GLOBALS['blog_id']      = $new_blog_id;
523
524      if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
 
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_id, $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      $new_blog_id  = array_pop( $GLOBALS['_wp_switched_stack'] );
576      $prev_blog_id = get_current_blog_id();
577
578      if ( $new_blog_id == $prev_blog_id ) {
579           /** This filter is documented in wp-includes/ms-blogs.php */
580           do_action( 'switch_blog', $new_blog_id, $prev_blog_id );
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( $new_blog_id );
587      $GLOBALS['blog_id']      = $new_blog_id;
588      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
589
 
Line Code
605                     wp_cache_add_global_groups( $global_groups );
606                } else {
607                     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' ) );
608                }
609                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
610           }
611      }
612
613      /** This filter is documented in wp-includes/ms-blogs.php */
614      do_action( 'switch_blog', $new_blog_id, $prev_blog_id );
615
616      // If we still have items in the switched stack, consider ourselves still 'switched'
617      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
618
619      return true;
620 }
621
622 /**
623  * Switches the initialized roles and current user capabilities to another site.