WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/14/2015 07:51:30 AM (5 years ago)
Author:
jeremyfelt
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/network/site-info.php

    r32759 r32760  
    5959
    6060    $blog_data = wp_unslash( $_POST['blog'] );
     61    $blog_data['scheme'] = $parsed_scheme;
    6162
    6263    if ( $is_main_site ) {
     
    7980    } else {
    8081        // Only the path can be updated for a subdirectory configuration, so capture existing domain.
    81         $blog_data['scheme'] = $parsed_scheme;
    8282        $blog_data['domain'] = $details->domain;
    8383    }
     
    9595    update_blog_details( $id, $blog_data );
    9696
    97     if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
    98         $new_details = get_blog_details( $id, false );
    99         $blog_address = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    100         if ( get_option( 'siteurl' ) != $blog_address ) {
    101             update_option( 'siteurl', $blog_address );
    102         }
    103         if ( get_option( 'home' ) != $blog_address ) {
    104             update_option( 'home', $blog_address );
    105         }
     97    // Maybe update home and siteurl options.
     98    $new_details = get_blog_details( $id, false );
     99
     100    $old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) );
     101    $old_home_parsed = parse_url( $old_home_url );
     102
     103    if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
     104        $new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
     105        update_option( 'home', $new_home_url );
     106    }
     107
     108    $old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
     109    $old_site_parsed = parse_url( $old_site_url );
     110
     111    if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
     112        $new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
     113        update_option( 'siteurl', $new_site_url );
    106114    }
    107115
     
    184192            <td>
    185193                <input name="blog[path]" type="text" id="path" value="<?php echo esc_attr( $details->path ) ?>" /><br />
    186             </td>
    187         </tr>
    188         <?php endif; ?>
    189 
    190         <?php if ( ! $is_main_site ) : ?>
    191         <tr class="form-field">
    192             <th scope="row"></th>
    193             <td>
    194                 <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>
    195194            </td>
    196195        </tr>
Note: See TracChangeset for help on using the changeset viewer.