Remove the "Update siteurl and home as well" checkbox when editing a site

Rather than provide a checkbox to update the `siteurl` and `home` options, we can make an educated decision based on the current state. If the home and/or siteurl domain and path match the existing domain and path of the site, then we update with the new information.

Also, while scheme is not stored in `wp_blogs` along with a site, the scheme of the `home` and `siteurl` options can now be modified via the Site URL setting in `site-info.php` when the `home` and/or `siteurl` options match the existing domain.

Props @hugobaeta, @earnjam, @jeremyfelt.
Fixes #32503, see #22383.

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


git-svn-id: http://core.svn.wordpress.org/trunk@32731 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jeremy Felt 2015-06-14 07:52:24 +00:00
parent 186c37a325
commit da35c25fb7
2 changed files with 19 additions and 20 deletions

View File

@ -58,6 +58,7 @@ if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
delete_option( 'rewrite_rules' );
$blog_data = wp_unslash( $_POST['blog'] );
$blog_data['scheme'] = $parsed_scheme;
if ( $is_main_site ) {
// On the network's main site, don't allow the domain or path to change.
@ -78,7 +79,6 @@ if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
$blog_data['path'] = $update_parsed_url['path'];
} else {
// Only the path can be updated for a subdirectory configuration, so capture existing domain.
$blog_data['scheme'] = $parsed_scheme;
$blog_data['domain'] = $details->domain;
}
@ -94,15 +94,23 @@ if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
update_blog_details( $id, $blog_data );
if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
$new_details = get_blog_details( $id, false );
$blog_address = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
if ( get_option( 'siteurl' ) != $blog_address ) {
update_option( 'siteurl', $blog_address );
}
if ( get_option( 'home' ) != $blog_address ) {
update_option( 'home', $blog_address );
}
// Maybe update home and siteurl options.
$new_details = get_blog_details( $id, false );
$old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) );
$old_home_parsed = parse_url( $old_home_url );
if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
$new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
update_option( 'home', $new_home_url );
}
$old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
$old_site_parsed = parse_url( $old_site_url );
if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
$new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
update_option( 'siteurl', $new_site_url );
}
restore_current_blog();
@ -187,15 +195,6 @@ switch_to_blog( $id );
</tr>
<?php endif; ?>
<?php if ( ! $is_main_site ) : ?>
<tr class="form-field">
<th scope="row"></th>
<td>
<input type="checkbox" name="update_home_url" id="update_home_url" value="update" <?php if ( get_option( 'siteurl' ) == untrailingslashit( get_blogaddress_by_id ($id ) ) || get_option( 'home' ) == untrailingslashit( get_blogaddress_by_id( $id ) ) ) echo 'checked="checked"'; ?> /> <label for="update_home_url"><?php _e( 'Update <code>siteurl</code> and <code>home</code> as well.' ); ?></label>
</td>
</tr>
<?php endif; ?>
<tr class="form-field">
<th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
<td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" /></td>

View File

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