From 440c8692e3b2c82dc190ea09a18732b8b129d42c Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Sat, 12 Aug 2017 13:10:24 +0000 Subject: [PATCH] Multisite: Remove references to `$wpdb->siteid` and use `get_current_network_id()` instead. Props sathyapulse, spacedmonkey. Fixes #41507. git-svn-id: https://develop.svn.wordpress.org/trunk@41242 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ms.php | 6 +----- src/wp-includes/ms-blogs.php | 2 +- src/wp-includes/ms-deprecated.php | 10 +++------ src/wp-includes/ms-functions.php | 4 ++-- src/wp-includes/option.php | 2 +- src/wp-signup.php | 4 ++-- tests/phpunit/tests/multisite/network.php | 25 ++--------------------- tests/phpunit/tests/option/multisite.php | 4 ++-- 8 files changed, 14 insertions(+), 43 deletions(-) diff --git a/src/wp-admin/includes/ms.php b/src/wp-admin/includes/ms.php index 596f9e5dc5..4c19b5685b 100644 --- a/src/wp-admin/includes/ms.php +++ b/src/wp-admin/includes/ms.php @@ -792,15 +792,11 @@ function choose_primary_blog() { * * @since 3.1.0 * - * @global wpdb $wpdb WordPress database abstraction object. - * * @param int $network_id The network ID to check. * @return bool True if network can be edited, otherwise false. */ function can_edit_network( $network_id ) { - global $wpdb; - - if ( $network_id == $wpdb->siteid ) + if ( $network_id == get_current_network_id() ) $result = true; else $result = false; diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index f5bf972227..a3f40b8358 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -1091,7 +1091,7 @@ function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { if ( ! empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, 'MU' ); // never used - return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A ); + return $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", get_current_network_id(), $start, $quantity ), ARRAY_A ); } /** diff --git a/src/wp-includes/ms-deprecated.php b/src/wp-includes/ms-deprecated.php index b6c9960897..9eff20eb16 100644 --- a/src/wp-includes/ms-deprecated.php +++ b/src/wp-includes/ms-deprecated.php @@ -187,7 +187,7 @@ function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) { _deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' ); global $wpdb; - $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A ); + $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", get_current_network_id() ), ARRAY_A ); $blog_list = array(); foreach ( (array) $blogs as $details ) { @@ -430,7 +430,7 @@ function get_admin_users_for_domain( $domain = '', $path = '' ) { global $wpdb; if ( ! $domain ) - $network_id = $wpdb->siteid; + $network_id = get_current_network_id(); else $network_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) ); @@ -447,8 +447,6 @@ function get_admin_users_for_domain( $domain = '', $path = '' ) { * @deprecated 4.6.0 Use get_sites() * @see get_sites() * - * @global wpdb $wpdb WordPress database abstraction object. - * * @param array $args { * Array of default arguments. Optional. * @@ -468,15 +466,13 @@ function get_admin_users_for_domain( $domain = '', $path = '' ) { * values for whether the site is public, archived, mature, spam, and/or deleted. */ function wp_get_sites( $args = array() ) { - global $wpdb; - _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' ); if ( wp_is_large_network() ) return array(); $defaults = array( - 'network_id' => $wpdb->siteid, + 'network_id' => get_current_network_id(), 'public' => null, 'archived' => null, 'mature' => null, diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index 1841580fe0..a0190571da 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -72,7 +72,7 @@ function get_active_blog_for_user( $user_id ) { $ret = false; if ( is_array( $blogs ) && count( $blogs ) > 0 ) { foreach ( (array) $blogs as $blog_id => $blog ) { - if ( $blog->site_id != $wpdb->siteid ) + if ( $blog->site_id != get_current_network_id() ) continue; $details = get_site( $blog_id ); if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) { @@ -1089,7 +1089,7 @@ function wpmu_activate_signup($key) { return array( 'user_id' => $user_id, 'password' => $password, 'meta' => $meta ); } - $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid ); + $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, get_current_network_id() ); // TODO: What to do if we create a user but cannot create a blog? if ( is_wp_error($blog_id) ) { diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 5c96f2270c..1ea13263a5 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -223,7 +223,7 @@ function wp_load_core_site_options( $network_id = null ) { return; if ( empty($network_id) ) - $network_id = $wpdb->siteid; + $network_id = get_current_network_id(); $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' ); diff --git a/src/wp-signup.php b/src/wp-signup.php index 5ec0f2ddec..e119b982a8 100644 --- a/src/wp-signup.php +++ b/src/wp-signup.php @@ -354,7 +354,7 @@ function signup_another_blog( $blogname = '', $blog_title = '', $errors = '' ) { * The function halts all execution if the user is not logged in. */ function validate_another_blog_signup() { - global $wpdb, $blogname, $blog_title, $errors, $domain, $path; + global $blogname, $blog_title, $errors, $domain, $path; $current_user = wp_get_current_user(); if ( ! is_user_logged_in() ) { die(); @@ -422,7 +422,7 @@ function validate_another_blog_signup() { */ $meta = apply_filters( 'add_signup_meta', $meta_defaults ); - $blog_id = wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid ); + $blog_id = wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, get_current_network_id() ); if ( is_wp_error( $blog_id ) ) { return false; diff --git a/tests/phpunit/tests/multisite/network.php b/tests/phpunit/tests/multisite/network.php index 6c6d51190b..671cd36419 100644 --- a/tests/phpunit/tests/multisite/network.php +++ b/tests/phpunit/tests/multisite/network.php @@ -189,16 +189,7 @@ class Tests_Multisite_Network extends WP_UnitTestCase { * @ticket 37865 */ public function test_get_blog_count_on_different_network() { - global $current_site, $wpdb; - - // switch_to_network()... - $orig_network_id = $current_site->id; - $orig_wpdb_network_id = $wpdb->siteid; - $current_site->id = self::$different_network_id; - $wpdb->siteid = self::$different_network_id; - wp_update_network_site_counts(); - $current_site->id = $orig_network_id; - $wpdb->siteid = $orig_wpdb_network_id; + wp_update_network_site_counts( self::$different_network_id ); $site_count = get_blog_count( self::$different_network_id ); @@ -209,25 +200,13 @@ class Tests_Multisite_Network extends WP_UnitTestCase { * @ticket 37866 */ public function test_get_user_count_on_different_network() { - global $current_site, $wpdb; - wp_update_network_user_counts(); $current_network_user_count = get_user_count(); - // switch_to_network()... - $orig_network_id = $current_site->id; - $orig_wpdb_network_id = $wpdb->siteid; - $current_site->id = self::$different_network_id; - $wpdb->siteid = self::$different_network_id; - // Add another user to fake the network user count to be different. wpmu_create_user( 'user', 'pass', 'email' ); - wp_update_network_user_counts(); - - // restore_current_network()... - $current_site->id = $orig_network_id; - $wpdb->siteid = $orig_wpdb_network_id; + wp_update_network_user_counts( self::$different_network_id ); $user_count = get_user_count( self::$different_network_id ); diff --git a/tests/phpunit/tests/option/multisite.php b/tests/phpunit/tests/option/multisite.php index 0669a7adc6..f751fa6cca 100644 --- a/tests/phpunit/tests/option/multisite.php +++ b/tests/phpunit/tests/option/multisite.php @@ -148,8 +148,8 @@ class Tests_Multisite_Option extends WP_UnitTestCase { * @group multisite */ function test_site_notoptions() { - global $wpdb; - $notoptions_key = "{$wpdb->siteid}:notoptions"; + $network_id = get_current_network_id(); + $notoptions_key = "{$network_id}:notoptions"; $_notoptions = wp_cache_get( 'notoptions', 'site-options' ); $this->assertEmpty( $_notoptions );