From 4b0eaacd84860bcdf55e53b5620603b2dfd92c15 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Sun, 14 Jun 2015 07:51:30 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@32760 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/network/site-info.php | 37 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/wp-admin/network/site-info.php b/src/wp-admin/network/site-info.php index 38b1526a6f..ebe4c7bc88 100644 --- a/src/wp-admin/network/site-info.php +++ b/src/wp-admin/network/site-info.php @@ -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 ); - - - - - /> - - - -