Multisite: Use get_network() and get_current_network_id() for current network data.

`get_network()` falls back to the current network when called without any arguments. Between this and `get_current_network_id()`, we can replace almost all instances of the global `$current_site` and all instances of `get_current_site()`.

This effectively deprecates `get_current_site()`, something that we'll do in a future ticket.

Props flixos90.
Fixes #37414.

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


git-svn-id: http://core.svn.wordpress.org/trunk@38757 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jeremy Felt
2016-10-19 04:47:30 +00:00
parent 1c3b96537f
commit 1560fbcbc5
26 changed files with 102 additions and 115 deletions

View File

@@ -104,7 +104,7 @@ if ( isset( $_GET['updated'] ) ) {
<tr>
<th scope="row"><label for="site_name"><?php _e( 'Network Title' ) ?></label></th>
<td>
<input name="site_name" type="text" id="site_name" class="regular-text" value="<?php echo esc_attr( $current_site->site_name ) ?>" />
<input name="site_name" type="text" id="site_name" class="regular-text" value="<?php echo esc_attr( get_network()->site_name ) ?>" />
</td>
</tr>

View File

@@ -86,11 +86,11 @@ if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
}
if ( is_subdomain_install() ) {
$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
$path = $current_site->path;
$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', get_network()->domain );
$path = get_network()->path;
} else {
$newdomain = $current_site->domain;
$path = $current_site->path . $domain . '/';
$newdomain = get_network()->domain;
$path = get_network()->path . $domain . '/';
}
$password = 'N/A';
@@ -126,7 +126,7 @@ if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
}
$wpdb->hide_errors();
$id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, $current_site->id );
$id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, get_current_network_id() );
$wpdb->show_errors();
if ( ! is_wp_error( $id ) ) {
if ( ! is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) ) {
@@ -138,7 +138,7 @@ if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
sprintf(
/* translators: %s: network name */
__( '[%s] New Site Created' ),
$current_site->site_name
get_network()->site_name
),
sprintf(
/* translators: 1: user login, 2: site url, 3: site name/title */
@@ -198,9 +198,9 @@ if ( ! empty( $messages ) ) {
<th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ) ?></label></th>
<td>
<?php if ( is_subdomain_install() ) { ?>
<input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off"/><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', $current_site->domain ); ?></span>
<input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off"/><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', get_network()->domain ); ?></span>
<?php } else {
echo $current_site->domain . $current_site->path ?><input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" />
echo get_network()->domain . get_network()->path ?><input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" />
<?php }
echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>';
?>

View File

@@ -87,7 +87,7 @@ if ( isset( $_GET['action'] ) ) {
header( 'Content-Type: text/html; charset=utf-8' );
}
if ( $current_site->blog_id == $id ) {
if ( get_network()->site_id == $id ) {
wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
}
@@ -126,7 +126,7 @@ if ( isset( $_GET['action'] ) ) {
wp_die( __( 'Sorry, you are not allowed to access this page.' ), '', array( 'response' => 403 ) );
$updated_action = 'not_deleted';
if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) {
if ( $id != '0' && $id != get_network()->site_id && current_user_can( 'delete_site', $id ) ) {
wpmu_delete_blog( $id, true );
$updated_action = 'delete';
}
@@ -137,7 +137,7 @@ if ( isset( $_GET['action'] ) ) {
$doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
foreach ( (array) $_POST['allblogs'] as $key => $val ) {
if ( $val != '0' && $val != $current_site->blog_id ) {
if ( $val != '0' && $val != get_network()->site_id ) {
switch ( $doaction ) {
case 'delete':
if ( ! current_user_can( 'delete_site', $val ) )

View File

@@ -72,7 +72,7 @@ if ( isset( $_GET['action'] ) ) {
$userfunction = 'all_spam';
$blogs = get_blogs_of_user( $user_id, true );
foreach ( (array) $blogs as $details ) {
if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
if ( $details->userblog_id != get_network()->site_id ) // main blog not a spam !
update_blog_status( $details->userblog_id, 'spam', '1' );
}
update_user_status( $user_id, 'spam', '1' );