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. git-svn-id: https://develop.svn.wordpress.org/trunk@41661 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ea23ff3422
commit
e02c481487
|
@ -433,10 +433,13 @@ function wp_upgrade() {
|
||||||
wp_cache_flush();
|
wp_cache_flush();
|
||||||
|
|
||||||
if ( is_multisite() ) {
|
if ( is_multisite() ) {
|
||||||
if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) )
|
$site_id = get_current_blog_id();
|
||||||
$wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" );
|
|
||||||
else
|
if ( $wpdb->get_row( $wpdb->prepare( 'SELECT blog_id FROM %s WHERE blog_id = %d', $wpdb->blog_versions, $site_id ) ) ) {
|
||||||
$wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" );
|
$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;
|
$start += 20;
|
||||||
}
|
}
|
||||||
refresh_blog_details( $wpdb->blogid );
|
refresh_blog_details();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ if ( ! current_user_can( 'delete_site' ) )
|
||||||
|
|
||||||
if ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option( 'delete_blog_hash' ) != false ) {
|
if ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option( 'delete_blog_hash' ) != false ) {
|
||||||
if ( hash_equals( get_option( 'delete_blog_hash' ), $_GET['h'] ) ) {
|
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 ) );
|
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 {
|
} else {
|
||||||
wp_die( __( "I'm sorry, the link you clicked is stale. Please select another option." ) );
|
wp_die( __( "I'm sorry, the link you clicked is stale. Please select another option." ) );
|
||||||
|
|
|
@ -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_signup_user_notification', '__return_false' ); // Disable confirmation email
|
||||||
add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome 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' ) ) {
|
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 ) );
|
$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 );
|
$new_user = wpmu_activate_signup( $key );
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
* Update the last_updated field for the current site.
|
* Update the last_updated field for the current site.
|
||||||
*
|
*
|
||||||
* @since MU (3.0.0)
|
* @since MU (3.0.0)
|
||||||
*
|
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
|
||||||
*/
|
*/
|
||||||
function wpmu_update_blogs_date() {
|
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.
|
* Fires after the blog details are updated.
|
||||||
*
|
*
|
||||||
|
@ -26,7 +24,7 @@ function wpmu_update_blogs_date() {
|
||||||
*
|
*
|
||||||
* @param int $blog_id Site ID.
|
* @param int $blog_id Site ID.
|
||||||
*/
|
*/
|
||||||
do_action( 'wpmu_blog_updated', $wpdb->blogid );
|
do_action( 'wpmu_blog_updated', $site_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,12 +14,8 @@
|
||||||
* wp-includes/ms-files.php (wp-content/blogs.php in MU).
|
* wp-includes/ms-files.php (wp-content/blogs.php in MU).
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
|
||||||
*/
|
*/
|
||||||
function ms_upload_constants() {
|
function ms_upload_constants() {
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
// This filter is attached in ms-default-filters.php but that file is not included during SHORTINIT.
|
// 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' );
|
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.
|
// 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.
|
// This is handled in wp_upload_dir() by ignoring UPLOADS for this case.
|
||||||
if ( ! defined( 'UPLOADS' ) ) {
|
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
|
// Uploads dir relative to ABSPATH
|
||||||
if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR && ! defined( 'BLOGUPLOADDIR' ) )
|
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/' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,19 +34,17 @@ function get_sitestats() {
|
||||||
*
|
*
|
||||||
* @since MU (3.0.0) 1.0
|
* @since MU (3.0.0) 1.0
|
||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
|
||||||
*
|
|
||||||
* @param int $user_id The unique ID of the user
|
* @param int $user_id The unique ID of the user
|
||||||
* @return WP_Site|void The blog object
|
* @return WP_Site|void The blog object
|
||||||
*/
|
*/
|
||||||
function get_active_blog_for_user( $user_id ) {
|
function get_active_blog_for_user( $user_id ) {
|
||||||
global $wpdb;
|
|
||||||
$blogs = get_blogs_of_user( $user_id );
|
$blogs = get_blogs_of_user( $user_id );
|
||||||
if ( empty( $blogs ) )
|
if ( empty( $blogs ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( !is_multisite() )
|
if ( ! is_multisite() ) {
|
||||||
return $blogs[$wpdb->blogid];
|
return $blogs[ get_current_blog_id() ];
|
||||||
|
}
|
||||||
|
|
||||||
$primary_blog = get_user_meta( $user_id, 'primary_blog', true );
|
$primary_blog = get_user_meta( $user_id, 'primary_blog', true );
|
||||||
$first_blog = current($blogs);
|
$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();
|
$current_user = wp_get_current_user();
|
||||||
if ( $blog_id == 0 ) {
|
if ( $blog_id == 0 ) {
|
||||||
$blog_id = $wpdb->blogid;
|
$blog_id = get_current_blog_id();
|
||||||
}
|
}
|
||||||
$local_key = $wpdb->get_blog_prefix( $blog_id ) . $key;
|
$local_key = $wpdb->get_blog_prefix( $blog_id ) . $key;
|
||||||
|
|
||||||
|
|
|
@ -363,7 +363,7 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
||||||
wpmu_update_blogs_date();
|
wpmu_update_blogs_date();
|
||||||
|
|
||||||
// compare the update time with the current time, allow delta < 2
|
// compare the update time with the current time, allow delta < 2
|
||||||
$blog = get_site( $wpdb->blogid );
|
$blog = get_site( get_current_blog_id() );
|
||||||
$current_time = time();
|
$current_time = time();
|
||||||
$time_difference = $current_time - strtotime( $blog->last_updated );
|
$time_difference = $current_time - strtotime( $blog->last_updated );
|
||||||
$this->assertLessThan( 2, $time_difference );
|
$this->assertLessThan( 2, $time_difference );
|
||||||
|
|
|
@ -120,7 +120,7 @@ class Tests_Multisite_User extends WP_UnitTestCase {
|
||||||
wp_set_current_user( $user1_id );
|
wp_set_current_user( $user1_id );
|
||||||
|
|
||||||
$this->assertTrue( is_blog_user() );
|
$this->assertTrue( is_blog_user() );
|
||||||
$this->assertTrue( is_blog_user( $wpdb->blogid ) );
|
$this->assertTrue( is_blog_user( get_current_blog_id() ) );
|
||||||
|
|
||||||
$blog_ids = array();
|
$blog_ids = array();
|
||||||
|
|
||||||
|
@ -149,12 +149,13 @@ class Tests_Multisite_User extends WP_UnitTestCase {
|
||||||
$this->assertFalse( is_user_member_of_blog() );
|
$this->assertFalse( is_user_member_of_blog() );
|
||||||
|
|
||||||
wp_set_current_user( $user1_id );
|
wp_set_current_user( $user1_id );
|
||||||
|
$site_id = get_current_blog_id();
|
||||||
|
|
||||||
$this->assertTrue( is_user_member_of_blog() );
|
$this->assertTrue( is_user_member_of_blog() );
|
||||||
$this->assertTrue( is_user_member_of_blog( 0, 0 ) );
|
$this->assertTrue( is_user_member_of_blog( 0, 0 ) );
|
||||||
$this->assertTrue( is_user_member_of_blog( 0, $wpdb->blogid ) );
|
$this->assertTrue( is_user_member_of_blog( 0, $site_id ) );
|
||||||
$this->assertTrue( is_user_member_of_blog( $user1_id ) );
|
$this->assertTrue( is_user_member_of_blog( $user1_id ) );
|
||||||
$this->assertTrue( is_user_member_of_blog( $user1_id, $wpdb->blogid ) );
|
$this->assertTrue( is_user_member_of_blog( $user1_id, $site_id ) );
|
||||||
|
|
||||||
$blog_ids = self::factory()->blog->create_many( 1 );
|
$blog_ids = self::factory()->blog->create_many( 1 );
|
||||||
foreach ( $blog_ids as $blog_id ) {
|
foreach ( $blog_ids as $blog_id ) {
|
||||||
|
|
Loading…
Reference in New Issue