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
472      if ( empty($switched_stack) )
473           $switched_stack = array();
474
475      $switched_stack[] = $blog_id;
476
477      /* If we're switching to the same blog id that we're on,
478      * set the right vars, do the associated actions, but skip
479      * the extra unnecessary work */
480      if ( $blog_id == $new_blog ) {
481           do_action( 'switch_blog', $blog_id, $blog_id );
482           $switched = true;
483           return true;
484      }
485
486      $wpdb->set_blog_id($new_blog);
487      $table_prefix = $wpdb->prefix;
488      $prev_blog_id = $blog_id;
489      $blog_id = $new_blog;
490
 
Line Code
511      wp_cache_init();
512      if ( function_exists('wp_cache_add_global_groups') ) {
513           if ( is_array( $global_groups ) )
514                wp_cache_add_global_groups( $global_groups );
515           else
516                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
517           wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
518      }
519
520      do_action('switch_blog', $blog_id, $prev_blog_id);
521      $switched = true;
522      return true;
523 }
524
525 /**
526  * Restore the current blog, after calling switch_to_blog()
527  *
528  * @see switch_to_blog()
529  * @since MU
 
Line Code
535
536      if ( !$switched )
537           return false;
538
539      if ( !is_array( $switched_stack ) )
540           return false;
541
542      $blog = array_pop( $switched_stack );
543      if ( $blog_id == $blog ) {
544           do_action( 'switch_blog', $blog, $blog );
545           /* If we still have items in the switched stack, consider ourselves still 'switched' */
546           $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 );
547           return true;
548      }
549
550      $wpdb->set_blog_id($blog);
551      $prev_blog_id = $blog_id;
552      $blog_id = $blog;
553      $table_prefix = $wpdb->prefix;
 
Line Code
575      wp_cache_init();
576      if ( function_exists('wp_cache_add_global_groups') ) {
577           if ( is_array( $global_groups ) )
578                wp_cache_add_global_groups( $global_groups );
579           else
580                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
581           wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
582      }
583
584      do_action('switch_blog', $blog_id, $prev_blog_id);
585
586      /* If we still have items in the switched stack, consider ourselves still 'switched' */
587      $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 );
588      return true;
589 }
590
591 /**
592  * Check if a particular blog is archived.
593  *