Make WordPress Core

Ticket #15936: 15936.2.diff

File 15936.2.diff, 2.7 KB (added by spacedmonkey, 6 years ago)
  • src/wp-admin/includes/network.php

     
    133133
    134134        $hostname  = get_clean_basedomain();
    135135        $has_ports = strstr( $hostname, ':' );
    136         if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
     136
     137        /** This filter is documented in wp-includes/ms-settings.php */
     138        $allowed_ports = apply_filters( 'allowed_multisite_ports', array( ':80', ':443' ) );
     139
     140        if ( ( false !== $has_ports && ! in_array( $has_ports, $allowed_ports ) ) ) {
    137141                echo '<div class="error"><p><strong>' . __( 'ERROR:' ) . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
    138142                echo '<p>' . sprintf(
    139143                        /* translators: %s: port number */
  • src/wp-includes/ms-blogs.php

     
    902902        // Sanitize domain if passed.
    903903        if ( array_key_exists( 'domain', $data ) ) {
    904904                $data['domain'] = trim( $data['domain'] );
     905                $data['domain'] = preg_replace( '|:\d+$|', '', $data['domain'] );
    905906                $data['domain'] = preg_replace( '/\s+/', '', sanitize_user( $data['domain'], true ) );
    906907                if ( is_subdomain_install() ) {
    907908                        $data['domain'] = str_replace( '@', '', $data['domain'] );
  • src/wp-includes/ms-settings.php

     
    5555if ( ! isset( $current_site ) || ! isset( $current_blog ) ) {
    5656
    5757        $domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) );
    58         if ( substr( $domain, -3 ) == ':80' ) {
    59                 $domain               = substr( $domain, 0, -3 );
    60                 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
    61         } elseif ( substr( $domain, -4 ) == ':443' ) {
    62                 $domain               = substr( $domain, 0, -4 );
    63                 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
     58
     59        /**
     60         * Filters allowed HTTP ports in Multisite.
     61         *
     62         * @since 5.1.0
     63         *
     64         * @param array $allowed_ports The allowed ports. Default is [ ':80', ':443' ].
     65         */
     66        $allowed_ports = apply_filters( 'allowed_multisite_ports', array( ':80', ':443' ) );
     67
     68        foreach ( $allowed_ports as $allowed_port ) {
     69                $str_length = strlen( $allowed_port );
     70                if ( substr( $domain, -$str_length ) == $allowed_port ) {
     71                        $domain               = substr( $domain, 0, -$str_length );
     72                        $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -$str_length);
     73                }
    6474        }
    6575
    6676        $path = stripslashes( $_SERVER['REQUEST_URI'] );