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.

Built from https://develop.svn.wordpress.org/trunk@41661


git-svn-id: http://core.svn.wordpress.org/trunk@41495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jeremy Felt 2017-10-02 01:44:47 +00:00
parent 5f19289fc2
commit abdfe59c28
7 changed files with 22 additions and 25 deletions

View File

@ -433,10 +433,13 @@ function wp_upgrade() {
wp_cache_flush();
if ( is_multisite() ) {
if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) )
$wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" );
else
$wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" );
$site_id = get_current_blog_id();
if ( $wpdb->get_row( $wpdb->prepare( 'SELECT blog_id FROM %s WHERE blog_id = %d', $wpdb->blog_versions, $site_id ) ) ) {
$wpdb->query( $wpdb->prepare( 'UPDATE %s SET db_version = %d WHERE blog_id = %d', $wpdb->blog_versions, $wp_db_version, $site_id ) );
} else {
$wpdb->query( $wpdb->prepare( 'INSERT INTO %s ( `blog_id` , `db_version` , `last_updated` ) VALUES ( %d, %d, %s);', $wpdb->blog_versions, $site_id, $wp_db_version, NOW() ) );
}
}
/**
@ -1257,7 +1260,7 @@ function upgrade_280() {
}
$start += 20;
}
refresh_blog_details( $wpdb->blogid );
refresh_blog_details();
}
}

View File

@ -17,7 +17,7 @@ if ( ! current_user_can( 'delete_site' ) )
if ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option( 'delete_blog_hash' ) != false ) {
if ( hash_equals( get_option( 'delete_blog_hash' ), $_GET['h'] ) ) {
wpmu_delete_blog( $wpdb->blogid );
wpmu_delete_blog( get_current_blog_id() );
wp_die( sprintf( __( 'Thank you for using %s, your site has been deleted. Happy trails to you until we meet again.' ), get_network()->site_name ) );
} else {
wp_die( __( "I'm sorry, the link you clicked is stale. Please select another option." ) );

View File

@ -156,7 +156,7 @@ Please click the following link to confirm the invite:
add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email
add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email
}
wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'] ) );
wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => get_current_blog_id(), 'new_role' => $_REQUEST['role'] ) );
if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) {
$key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email ) );
$new_user = wpmu_activate_signup( $key );

View File

@ -12,13 +12,11 @@
* Update the last_updated field for the current site.
*
* @since MU (3.0.0)
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function wpmu_update_blogs_date() {
global $wpdb;
$site_id = get_current_blog_id();
update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) );
update_blog_details( $site_id, array( 'last_updated' => current_time( 'mysql', true ) ) );
/**
* Fires after the blog details are updated.
*
@ -26,7 +24,7 @@ function wpmu_update_blogs_date() {
*
* @param int $blog_id Site ID.
*/
do_action( 'wpmu_blog_updated', $wpdb->blogid );
do_action( 'wpmu_blog_updated', $site_id );
}
/**

View File

@ -14,12 +14,8 @@
* wp-includes/ms-files.php (wp-content/blogs.php in MU).
*
* @since 3.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function ms_upload_constants() {
global $wpdb;
// This filter is attached in ms-default-filters.php but that file is not included during SHORTINIT.
add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );
@ -33,11 +29,13 @@ function ms_upload_constants() {
// Note, the main site in a post-MU network uses wp-content/uploads.
// This is handled in wp_upload_dir() by ignoring UPLOADS for this case.
if ( ! defined( 'UPLOADS' ) ) {
define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" );
$site_id = get_current_blog_id();
define( 'UPLOADS', UPLOADBLOGSDIR . '/' . $site_id . '/files/' );
// Uploads dir relative to ABSPATH
if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR && ! defined( 'BLOGUPLOADDIR' ) )
define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );
define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . '/blogs.dir/' . $site_id . '/files/' );
}
}

View File

@ -34,19 +34,17 @@ function get_sitestats() {
*
* @since MU (3.0.0) 1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $user_id The unique ID of the user
* @return WP_Site|void The blog object
*/
function get_active_blog_for_user( $user_id ) {
global $wpdb;
$blogs = get_blogs_of_user( $user_id );
if ( empty( $blogs ) )
return;
if ( !is_multisite() )
return $blogs[$wpdb->blogid];
if ( ! is_multisite() ) {
return $blogs[ get_current_blog_id() ];
}
$primary_blog = get_user_meta( $user_id, 'primary_blog', true );
$first_blog = current($blogs);
@ -2219,7 +2217,7 @@ function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) {
$current_user = wp_get_current_user();
if ( $blog_id == 0 ) {
$blog_id = $wpdb->blogid;
$blog_id = get_current_blog_id();
}
$local_key = $wpdb->get_blog_prefix( $blog_id ) . $key;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41660';
$wp_version = '4.9-alpha-41661';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.