Make WordPress Core


Ignore:
Timestamp:
10/02/2017 01:43:48 AM (8 years ago)
Author:
jeremyfelt
Message:

Multisite: Use get_current_blog_id() instead of $wpdb->blogid.

get_current_blog_id() is more appropriate for determining the ID of the current site in most cases. This eliminates the need for the global $wpdb in several functions and is better than the implicit global used in admin pages.

Props bnap00, spacedmonkey.
Fixes #41684.

File:
1 edited

Legend:

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

    r41617 r41661  
    3535 * @since MU (3.0.0) 1.0
    3636 *
    37  * @global wpdb $wpdb WordPress database abstraction object.
    38  *
    3937 * @param int $user_id The unique ID of the user
    4038 * @return WP_Site|void The blog object
    4139 */
    4240function get_active_blog_for_user( $user_id ) {
    43     global $wpdb;
    4441    $blogs = get_blogs_of_user( $user_id );
    4542    if ( empty( $blogs ) )
    4643        return;
    4744
    48     if ( !is_multisite() )
    49         return $blogs[$wpdb->blogid];
     45    if ( ! is_multisite() ) {
     46        return $blogs[ get_current_blog_id() ];
     47    }
    5048
    5149    $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
     
    22202218    $current_user = wp_get_current_user();
    22212219    if ( $blog_id == 0 ) {
    2222         $blog_id = $wpdb->blogid;
     2220        $blog_id = get_current_blog_id();
    22232221    }
    22242222    $local_key = $wpdb->get_blog_prefix( $blog_id ) . $key;
Note: See TracChangeset for help on using the changeset viewer.