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