Multisite: Rename internal `$site_id` variables referencing networks to `$network_id`.

This change improves code clarity by using the current naming conventions for networks.

Props lemacarl.
Fixes #41510.

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


git-svn-id: http://core.svn.wordpress.org/trunk@41081 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2017-08-12 12:48:47 +00:00
parent f0ee106d86
commit 820d3973a3
6 changed files with 70 additions and 69 deletions

View File

@ -787,20 +787,20 @@ function choose_primary_blog() {
/**
* Whether or not we can edit this network from this page.
*
* By default editing of network is restricted to the Network Admin for that `$site_id`
* this allows for this to be overridden.
* By default editing of network is restricted to the Network Admin for that `$network_id`.
* This function allows for this to be overridden.
*
* @since 3.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $site_id The network/site ID to check.
* @param int $network_id The network ID to check.
* @return bool True if network can be edited, otherwise false.
*/
function can_edit_network( $site_id ) {
function can_edit_network( $network_id ) {
global $wpdb;
if ( $site_id == $wpdb->siteid )
if ( $network_id == $wpdb->siteid )
$result = true;
else
$result = false;
@ -810,10 +810,10 @@ function can_edit_network( $site_id ) {
*
* @since 3.1.0
*
* @param bool $result Whether the network can be edited from this page.
* @param int $site_id The network/site ID to check.
* @param bool $result Whether the network can be edited from this page.
* @param int $network_id The network ID to check.
*/
return apply_filters( 'can_edit_network', $result, $site_id );
return apply_filters( 'can_edit_network', $result, $network_id );
}
/**

View File

@ -420,22 +420,22 @@ function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $sitedomain Optional. Site domain.
* @param string $path Optional. Site path.
* @return array|false The network admins
* @param string $domain Optional. Network domain.
* @param string $path Optional. Network path.
* @return array|false The network admins.
*/
function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
function get_admin_users_for_domain( $domain = '', $path = '' ) {
_deprecated_function( __FUNCTION__, '4.4.0' );
global $wpdb;
if ( ! $sitedomain )
$site_id = $wpdb->siteid;
if ( ! $domain )
$network_id = $wpdb->siteid;
else
$site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
$network_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
if ( $site_id )
return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A );
if ( $network_id )
return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $network_id ), ARRAY_A );
return false;
}

View File

@ -1171,22 +1171,22 @@ function wpmu_create_user( $user_name, $password, $email ) {
*
* @since MU (3.0.0)
*
* @param string $domain The new site's domain.
* @param string $path The new site's path.
* @param string $title The new site's title.
* @param int $user_id The user ID of the new site's admin.
* @param array $meta Optional. Array of key=>value pairs used to set initial site options.
* If valid status keys are included ('public', 'archived', 'mature',
* 'spam', 'deleted', or 'lang_id') the given site status(es) will be
* updated. Otherwise, keys and values will be used to set options for
* the new site. Default empty array.
* @param int $site_id Optional. Network ID. Only relevant on multi-network installs.
* @param string $domain The new site's domain.
* @param string $path The new site's path.
* @param string $title The new site's title.
* @param int $user_id The user ID of the new site's admin.
* @param array $meta Optional. Array of key=>value pairs used to set initial site options.
* If valid status keys are included ('public', 'archived', 'mature',
* 'spam', 'deleted', or 'lang_id') the given site status(es) will be
* updated. Otherwise, keys and values will be used to set options for
* the new site. Default empty array.
* @param int $network_id Optional. Network ID. Only relevant on multi-network installs.
* @return int|WP_Error Returns WP_Error object on failure, the new site ID on success.
*/
function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $site_id = 1 ) {
function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $network_id = 1 ) {
$defaults = array(
'public' => 0,
'WPLANG' => get_network_option( $site_id, 'WPLANG' ),
'WPLANG' => get_network_option( $network_id, 'WPLANG' ),
);
$meta = wp_parse_args( $meta, $defaults );
@ -1202,14 +1202,14 @@ function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $s
$path = '/';
// Check if the domain has been used already. We should return an error message.
if ( domain_exists($domain, $path, $site_id) )
if ( domain_exists($domain, $path, $network_id) )
return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) );
if ( ! wp_installing() ) {
wp_installing( true );
}
if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
if ( ! $blog_id = insert_blog($domain, $path, $network_id) )
return new WP_Error('insert_blog', __('Could not create site.'));
switch_to_blog($blog_id);
@ -1236,14 +1236,14 @@ function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $s
*
* @since MU (3.0.0)
*
* @param int $blog_id Site ID.
* @param int $user_id User ID.
* @param string $domain Site domain.
* @param string $path Site path.
* @param int $site_id Network ID. Only relevant on multi-network installs.
* @param array $meta Meta data. Used to set initial site options.
* @param int $blog_id Site ID.
* @param int $user_id User ID.
* @param string $domain Site domain.
* @param string $path Site path.
* @param int $network_id Network ID. Only relevant on multi-network installs.
* @param array $meta Meta data. Used to set initial site options.
*/
do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );
do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $network_id, $meta );
wp_cache_set( 'last_changed', microtime(), 'sites' );
@ -1350,18 +1350,18 @@ Disable these notifications: %3$s'), $user->user_login, wp_unslash( $_SERVER['RE
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $domain The domain to be checked.
* @param string $path The path to be checked.
* @param int $site_id Optional. Relevant only on multi-network installs.
* @param string $domain The domain to be checked.
* @param string $path The path to be checked.
* @param int $network_id Optional. Network ID. Relevant only on multi-network installs.
* @return int
*/
function domain_exists($domain, $path, $site_id = 1) {
function domain_exists( $domain, $path, $network_id = 1 ) {
$path = trailingslashit( $path );
$args = array(
'network_id' => $site_id,
'domain' => $domain,
'path' => $path,
'fields' => 'ids',
'network_id' => $network_id,
'domain' => $domain,
'path' => $path,
'fields' => 'ids',
);
$result = get_sites( $args );
$result = array_shift( $result );
@ -1371,12 +1371,12 @@ function domain_exists($domain, $path, $site_id = 1) {
*
* @since 3.5.0
*
* @param int|null $result The blog_id if the blogname exists, null otherwise.
* @param string $domain Domain to be checked.
* @param string $path Path to be checked.
* @param int $site_id Site ID. Relevant only on multi-network installs.
* @param int|null $result The blog_id if the blogname exists, null otherwise.
* @param string $domain Domain to be checked.
* @param string $path Path to be checked.
* @param int $network_id Network ID. Relevant only on multi-network installs.
*/
return apply_filters( 'domain_exists', $result, $domain, $path, $site_id );
return apply_filters( 'domain_exists', $result, $domain, $path, $network_id );
}
/**
@ -1389,25 +1389,25 @@ function domain_exists($domain, $path, $site_id = 1) {
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $domain The domain of the new site.
* @param string $path The path of the new site.
* @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1.
* @param string $domain The domain of the new site.
* @param string $path The path of the new site.
* @param int $network_id Unless you're running a multi-network install, be sure to set this value to 1.
* @return int|false The ID of the new row
*/
function insert_blog($domain, $path, $site_id) {
function insert_blog($domain, $path, $network_id) {
global $wpdb;
$path = trailingslashit($path);
$site_id = (int) $site_id;
$network_id = (int) $network_id;
$result = $wpdb->insert( $wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) );
$result = $wpdb->insert( $wpdb->blogs, array('site_id' => $network_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) );
if ( ! $result )
return false;
$blog_id = $wpdb->insert_id;
refresh_blog_details( $blog_id );
wp_maybe_update_network_site_counts( $site_id );
wp_maybe_update_network_site_counts( $network_id );
return $blog_id;
}

View File

@ -214,25 +214,25 @@ function wp_load_alloptions() {
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $site_id Optional site ID for which to query the options. Defaults to the current site.
* @param int $network_id Optional site ID for which to query the options. Defaults to the current site.
*/
function wp_load_core_site_options( $site_id = null ) {
function wp_load_core_site_options( $network_id = null ) {
global $wpdb;
if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() )
return;
if ( empty($site_id) )
$site_id = $wpdb->siteid;
if ( empty($network_id) )
$network_id = $wpdb->siteid;
$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' );
$core_options_in = "'" . implode("', '", $core_options) . "'";
$options = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $site_id) );
$options = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) );
foreach ( $options as $option ) {
$key = $option->meta_key;
$cache_key = "{$site_id}:$key";
$cache_key = "{$network_id}:$key";
$option->meta_value = maybe_unserialize( $option->meta_value );
wp_cache_set( $cache_key, $option->meta_value, 'site-options' );

View File

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

View File

@ -893,12 +893,13 @@ class wpdb {
* @since 3.0.0
*
* @param int $blog_id
* @param int $site_id Optional.
* @param int $network_id Optional.
* @return int previous blog id
*/
public function set_blog_id( $blog_id, $site_id = 0 ) {
if ( ! empty( $site_id ) )
$this->siteid = $site_id;
public function set_blog_id( $blog_id, $network_id = 0 ) {
if ( ! empty( $network_id ) ) {
$this->siteid = $network_id;
}
$old_blog_id = $this->blogid;
$this->blogid = $blog_id;