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
518            *
519            * @since MU (3.0.0)
520            * @since 5.4.0 The `$context` parameter was added.
521            *
522            * @param int    $new_blog_id  New blog ID.
523            * @param int    $prev_blog_id Previous blog ID.
524            * @param string $context      Additional context. Accepts 'switch' when called from switch_to_blog()
525            *                             or 'restore' when called from restore_current_blog().
526            */
527           do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
528
529           $GLOBALS['switched'] = true;
530
531           return true;
532      }
533
534      $wpdb->set_blog_id( $new_blog_id );
535      $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
536      $GLOBALS['blog_id']      = $new_blog_id;
 
Line Code
574                          )
575                     );
576                }
577
578                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
579           }
580      }
581
582      /** This filter is documented in wp-includes/ms-blogs.php */
583      do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
584
585      $GLOBALS['switched'] = true;
586
587      return true;
588 }
589
590 /**
591  * Restore the current blog, after calling switch_to_blog().
592  *
 
Line Code
608      if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
609           return false;
610      }
611
612      $new_blog_id  = array_pop( $GLOBALS['_wp_switched_stack'] );
613      $prev_blog_id = get_current_blog_id();
614
615      if ( $new_blog_id == $prev_blog_id ) {
616           /** This filter is documented in wp-includes/ms-blogs.php */
617           do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
618
619           // If we still have items in the switched stack, consider ourselves still 'switched'.
620           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
621
622           return true;
623      }
624
625      $wpdb->set_blog_id( $new_blog_id );
626      $GLOBALS['blog_id']      = $new_blog_id;
 
Line Code
665                          )
666                     );
667                }
668
669                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
670           }
671      }
672
673      /** This filter is documented in wp-includes/ms-blogs.php */
674      do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
675
676      // If we still have items in the switched stack, consider ourselves still 'switched'.
677      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
678
679      return true;
680 }
681
682 /**
683  * Switches the initialized roles and current user capabilities to another site.