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
578                          )
579                     );
580                }
581
582                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) );
583           }
584      }
585
586      /** This filter is documented in wp-includes/ms-blogs.php */
587      do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );
588
589      $GLOBALS['switched'] = true;
590
591      return true;
592 }
593
594 /**
595  * Restores the current blog, after calling switch_to_blog().
596  *
 
Line Code
612      if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
613           return false;
614      }
615
616      $new_blog_id  = array_pop( $GLOBALS['_wp_switched_stack'] );
617      $prev_blog_id = get_current_blog_id();
618
619      if ( $new_blog_id === $prev_blog_id ) {
620           /** This filter is documented in wp-includes/ms-blogs.php */
621           do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
622
623           // If we still have items in the switched stack, consider ourselves still 'switched'.
624           $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
625
626           return true;
627      }
628
629      $wpdb->set_blog_id( $new_blog_id );
630      $GLOBALS['blog_id']      = $new_blog_id;
 
Line Code
673                          )
674                     );
675                }
676
677                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) );
678           }
679      }
680
681      /** This filter is documented in wp-includes/ms-blogs.php */
682      do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
683
684      // If we still have items in the switched stack, consider ourselves still 'switched'.
685      $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
686
687      return true;
688 }
689
690 /**
691  * Switches the initialized roles and current user capabilities to another site.