Make WordPress Core


Ignore:
Timestamp:
05/04/2024 07:23:31 PM (7 months ago)
Author:
johnbillion
Message:

Bootstrap/Load: Add support for custom ports in multisite site addresses.

This allows a Multisite network to use an address that includes a port name, such as example.com:1234, and adds support for this to the local development environment too. You can now run a Multisite installation on the local development environment, for example at localhost:8889.

This also fixes some bugs with running a single site installation on a port, and updates the testing infrastructure so that the whole test suite runs both with and without a port number.

Props djzone, scribu, nacin, ipstenu, F J Kaiser, jeremyfelt, johnjamesjacoby, spacedmonkey, PerS, Clorith, Blackbam, enrico.sorcinelli, Jules Colle, obliviousharmony, desrosj, johnbillion

Fixes #21077, #52088

File:
1 edited

Legend:

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

    r56409 r58097  
    6767
    6868        $blog_data['scheme'] = $update_parsed_url['scheme'];
     69
     70        // Make sure to not lose the port if it was provided.
    6971        $blog_data['domain'] = $update_parsed_url['host'];
    70         $blog_data['path']   = $update_parsed_url['path'];
     72        if ( isset( $update_parsed_url['port'] ) ) {
     73            $blog_data['domain'] .= ':' . $update_parsed_url['port'];
     74        }
     75
     76        $blog_data['path'] = $update_parsed_url['path'];
    7177    }
    7278
     
    8995    $old_home_url    = trailingslashit( esc_url( get_option( 'home' ) ) );
    9096    $old_home_parsed = parse_url( $old_home_url );
    91 
    92     if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
     97    $old_home_host   = $old_home_parsed['host'] . ( isset( $old_home_parsed['port'] ) ? ':' . $old_home_parsed['port'] : '' );
     98
     99    if ( $old_home_host === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
    93100        $new_home_url = untrailingslashit( sanitize_url( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    94101        update_option( 'home', $new_home_url );
     
    97104    $old_site_url    = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
    98105    $old_site_parsed = parse_url( $old_site_url );
    99 
    100     if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
     106    $old_site_host   = $old_site_parsed['host'] . ( isset( $old_site_parsed['port'] ) ? ':' . $old_site_parsed['port'] : '' );
     107
     108    if ( $old_site_host === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
    101109        $new_site_url = untrailingslashit( sanitize_url( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    102110        update_option( 'siteurl', $new_site_url );
Note: See TracChangeset for help on using the changeset viewer.