Make WordPress Core


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

Capture domain and path when editing sites on a subdomain network

When a network is configured as subdomain, allow for the input of arbitrary domain and path combinations when editing a site rather than just the domain.

This takes a step or two toward #32503.

Props @scribu, @ericlewis, @jeremyfelt.
See #22383.

File:
1 edited

Legend:

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

    r32758 r32759  
    4747}
    4848
    49 $parsed = parse_url( $details->siteurl );
     49$parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME );
    5050$is_main_site = is_main_site( $id );
    5151
     
    5858    delete_option( 'rewrite_rules' );
    5959
    60     // Update blogs table.
    6160    $blog_data = wp_unslash( $_POST['blog'] );
     61
     62    if ( $is_main_site ) {
     63        // On the network's main site, don't allow the domain or path to change.
     64        $blog_data['domain'] = $details->domain;
     65        $blog_data['path'] = $details->path;
     66    } elseif ( is_subdomain_install() ) {
     67        // All parts of a URL can be updated for a subdomain configuration. We first
     68        // need to ensure a scheme has been provided, otherwise fallback to the existing.
     69        $new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME );
     70
     71        if ( ! $new_url_scheme ) {
     72            $blog_data['url'] = esc_url( $parsed_scheme . '://' . $blog_data['url'] );
     73        }
     74        $update_parsed_url = parse_url( $blog_data['url'] );
     75
     76        $blog_data['scheme'] = $update_parsed_url['scheme'];
     77        $blog_data['domain'] = $update_parsed_url['host'];
     78        $blog_data['path'] = $update_parsed_url['path'];
     79    } else {
     80        // Only the path can be updated for a subdirectory configuration, so capture existing domain.
     81        $blog_data['scheme'] = $parsed_scheme;
     82        $blog_data['domain'] = $details->domain;
     83    }
     84
    6285    $existing_details = get_blog_details( $id, false );
    6386    $blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
     
    6992        }
    7093    }
     94
    7195    update_blog_details( $id, $blog_data );
    7296
    7397    if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
    7498        $new_details = get_blog_details( $id, false );
    75         $blog_address = esc_url_raw( $new_details->domain . $new_details->path );
     99        $blog_address = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    76100        if ( get_option( 'siteurl' ) != $blog_address ) {
    77101            update_option( 'siteurl', $blog_address );
     
    126150        echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
    127151    }
    128 } ?>
     152}
     153
     154switch_to_blog( $id );
     155?>
    129156<form method="post" action="site-info.php?action=update-site">
    130157    <?php wp_nonce_field( 'edit-site' ); ?>
    131158    <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
    132159    <table class="form-table">
     160        <?php
     161        // The main site of the network should not be updated on this page.
     162        if ( $is_main_site ) : ?>
     163        <tr class="form-field">
     164            <th scope="row"><?php _e( 'Site URL' ); ?></th>
     165            <td><?php echo esc_url( $details->siteurl ); ?></td>
     166        </tr>
     167        <?php
     168        // In a subdomain configuration, the scheme, domain, and path can all be changed.
     169        elseif ( is_subdomain_install() ) : ?>
    133170        <tr class="form-field form-required">
    134             <?php if ( $is_main_site ) { ?>
    135                 <th scope="row"><?php _e( 'Domain' ) ?></th>
    136                 <td><code><?php echo $parsed['scheme'] . '://' . esc_attr( $details->domain ) ?></code></td>
    137             <?php } else { ?>
    138                 <th scope="row"><label for="domain"><?php _e( 'Domain' ) ?></label></th>
    139                 <td><?php echo $parsed['scheme'] . '://'; ?><input name="blog[domain]" type="text" id="domain" value="<?php echo esc_attr( $details->domain ) ?>" /></td>
    140             <?php } ?>
     171            <th scope="row"><?php _e( 'Site URL' ); ?></th>
     172            <td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
     173        </tr>
     174        <?php
     175        // In a subdirectory configuration, only the path can be changed.
     176        // Scheme and domain are inherited from the network.
     177        else : ?>
     178        <tr class="form-field">
     179            <th scope="row"><?php _e( 'Domain' ); ?></th>
     180            <td><?php echo $parsed_scheme . ':// ' . esc_attr( $details->domain ); ?></td>
    141181        </tr>
    142182        <tr class="form-field form-required">
    143             <?php if ( $is_main_site ) { ?>
    144             <th scope="row"><?php _e( 'Path' ) ?></th>
    145             <td><code><?php echo esc_attr( $details->path ) ?></code></td>
    146             <?php
    147             } else {
    148                 switch_to_blog( $id );
    149             ?>
    150183            <th scope="row"><label for="path"><?php _e( 'Path' ) ?></label></th>
    151184            <td>
    152185                <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>
    153194                <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>
    154195            </td>
    155             <?php
    156                 restore_current_blog();
    157             } ?>
    158         </tr>
     196        </tr>
     197        <?php endif; ?>
     198
    159199        <tr class="form-field">
    160200            <th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
     
    192232</div>
    193233<?php
     234restore_current_blog();
    194235require( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.