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

@@ -33,9 +33,9 @@ get_admin_page_title();
$title = esc_html( strip_tags( $title ) );
if ( is_network_admin() )
$admin_title = sprintf( __( 'Network Admin: %s' ), esc_html( get_current_site()->site_name ) );
$admin_title = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) );
elseif ( is_user_admin() )
$admin_title = sprintf( __( 'User Dashboard: %s' ), esc_html( get_current_site()->site_name ) );
$admin_title = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) );
else
$admin_title = get_bloginfo( 'name' );

View File

@@ -518,7 +518,7 @@ class WP_MS_Sites_List_Table extends WP_List_Table {
$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>';
$actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>';
if ( get_current_site()->blog_id != $blog['blog_id'] ) {
if ( get_network()->site_id != $blog['blog_id'] ) {
if ( $blog['deleted'] == '1' ) {
$actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>';
} else {

View File

@@ -329,7 +329,7 @@ class WP_MS_Users_List_Table extends WP_List_Table {
$path = ( $val->path === '/' ) ? '' : $val->path;
echo '<span class="site-' . $val->site_id . '" >';
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>';
echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_network()->domain, '', $val->domain . $path ) . '</a>';
echo ' <small class="row-actions">';
$actions = array();
$actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';

View File

@@ -88,7 +88,7 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
update_blog_status( $blog_id, 'deleted', 1 );
$current_site = get_current_site();
$current_network = get_network();
// If a full blog object is not available, do not destroy anything.
if ( $drop && ! $blog ) {
@@ -96,7 +96,7 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
}
// Don't destroy the initial, main, or root blog.
if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) {
if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_network->path && $blog->domain == $current_network->domain ) ) ) {
$drop = false;
}

View File

@@ -527,7 +527,7 @@ function populate_options() {
// 3.0 multisite
if ( is_multisite() ) {
/* translators: site tagline */
$options[ 'blogdescription' ] = sprintf(__('Just another %s site'), get_current_site()->site_name );
$options[ 'blogdescription' ] = sprintf(__('Just another %s site'), get_network()->site_name );
$options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/';
}

View File

@@ -161,12 +161,12 @@ function wp_install_defaults( $user_id ) {
}
$first_post = sprintf( $first_post,
sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_current_site()->site_name )
sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name )
);
// Back-compat for pre-4.4
$first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post );
$first_post = str_replace( 'SITE_NAME', get_current_site()->site_name, $first_post );
$first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post );
} else {
$first_post = __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' );
}

View File

@@ -18,7 +18,7 @@ if ( ! current_user_can( 'delete_site' ) )
if ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option( 'delete_blog_hash' ) != false ) {
if ( hash_equals( get_option( 'delete_blog_hash' ), $_GET['h'] ) ) {
wpmu_delete_blog( $wpdb->blogid );
wp_die( sprintf( __( 'Thank you for using %s, your site has been deleted. Happy trails to you until we meet again.' ), $current_site->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 {
wp_die( __( "I'm sorry, the link you clicked is stale. Please select another option." ) );
}
@@ -70,7 +70,7 @@ Webmaster
$content = str_replace( '###USERNAME###', $user->user_login, $content );
$content = str_replace( '###URL_DELETE###', $url_delete, $content );
$content = str_replace( '###SITE_NAME###', $current_site->site_name, $content );
$content = str_replace( '###SITE_NAME###', get_network()->site_name, $content );
wp_mail( get_option( 'admin_email' ), "[ " . wp_specialchars_decode( get_option( 'blogname' ) ) . " ] ".__( 'Delete My Site' ), $content );
?>
@@ -79,7 +79,7 @@ Webmaster
<?php } else {
?>
<p><?php printf( __( 'If you do not want to use your %s site any more, you can delete it using the form below. When you click <strong>Delete My Site Permanently</strong> you will be sent an email with a link in it. Click on this link to delete your site.'), $current_site->site_name); ?></p>
<p><?php printf( __( 'If you do not want to use your %s site any more, you can delete it using the form below. When you click <strong>Delete My Site Permanently</strong> you will be sent an email with a link in it. Click on this link to delete your site.'), get_network()->site_name); ?></p>
<p><?php _e( 'Remember, once deleted your site cannot be restored.' ) ?></p>
<form method="post" name="deletedirect">

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