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
This commit is contained in:
Felix Arntz 2017-08-12 13:10:24 +00:00
parent 9595e6c38b
commit 440c8692e3
8 changed files with 14 additions and 43 deletions

View File

@ -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;

View File

@ -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 );
}
/**

View File

@ -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,

View File

@ -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) ) {

View File

@ -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' );

View File

@ -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;

View File

@ -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 );

View File

@ -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 );