WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/31/2016 04:55:01 AM (3 years ago)
Author:
wonderboymusic
Message:

Multisite: use get_current_blog_id() where applicable, in lieu of plucking the $blog_id global from outer space.

See #37699.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-blogs.php

    r38388 r38457  
    767767    global $wpdb;
    768768
    769     if ( empty( $new_blog ) )
    770         $new_blog = $GLOBALS['blog_id'];
    771 
    772     $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id'];
     769    $blog_id = get_current_blog_id();
     770    if ( empty( $new_blog ) ) {
     771        $new_blog = $blog_id;
     772    }
     773
     774    $GLOBALS['_wp_switched_stack'][] = $blog_id;
    773775
    774776    /*
     
    777779     * the extra unnecessary work
    778780     */
    779     if ( $new_blog == $GLOBALS['blog_id'] ) {
     781    if ( $new_blog == $blog_id ) {
    780782        /**
    781783         * Fires when the blog is switched.
     
    793795    $wpdb->set_blog_id( $new_blog );
    794796    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    795     $prev_blog_id = $GLOBALS['blog_id'];
     797    $prev_blog_id = $blog_id;
    796798    $GLOBALS['blog_id'] = $new_blog;
    797799
     
    801803        global $wp_object_cache;
    802804
    803         if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
     805        if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) {
    804806            $global_groups = $wp_object_cache->global_groups;
    805         else
     807        } else {
    806808            $global_groups = false;
    807 
     809        }
    808810        wp_cache_init();
    809811
     
    849851    global $wpdb;
    850852
    851     if ( empty( $GLOBALS['_wp_switched_stack'] ) )
     853    if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
    852854        return false;
     855    }
    853856
    854857    $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
    855 
    856     if ( $GLOBALS['blog_id'] == $blog ) {
     858    $blog_id = get_current_blog_id();
     859
     860    if ( $blog_id == $blog ) {
    857861        /** This filter is documented in wp-includes/ms-blogs.php */
    858862        do_action( 'switch_blog', $blog, $blog );
     
    863867
    864868    $wpdb->set_blog_id( $blog );
    865     $prev_blog_id = $GLOBALS['blog_id'];
     869    $prev_blog_id = $blog_id;
    866870    $GLOBALS['blog_id'] = $blog;
    867871    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
     
    872876        global $wp_object_cache;
    873877
    874         if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
     878        if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) {
    875879            $global_groups = $wp_object_cache->global_groups;
    876         else
     880        } else {
    877881            $global_groups = false;
     882        }
    878883
    879884        wp_cache_init();
Note: See TracChangeset for help on using the changeset viewer.