diff --git a/src/wp-admin/includes/network.php b/src/wp-admin/includes/network.php index ae3e906fccd23..9fbd857e965e3 100644 --- a/src/wp-admin/includes/network.php +++ b/src/wp-admin/includes/network.php @@ -138,7 +138,10 @@ function network_step1( $errors = false ) { $hostname = get_clean_basedomain(); $has_ports = strstr( $hostname, ':' ); - if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ), true ) ) ) { + /** This filter is documented in wp-includes/ms-settings.php */ + $allowed_ports = apply_filters( 'allowed_multisite_ports', array( ':80', ':443' ) ); + + if ( ( false !== $has_ports && is_array( $allowed_ports ) && ! in_array( $has_ports, $allowed_ports, true ) ) ) { echo '

' . __( 'Error:' ) . ' ' . __( 'You cannot install a network of sites with your server address.' ) . '

'; echo '

' . sprintf( /* translators: %s: Port number. */ @@ -179,7 +182,7 @@ function network_step1( $errors = false ) { } ?>

-

+

' . substr( $hostname, 4 ) . '', '' . $hostname . '', 'www' @@ -444,7 +447,7 @@ function network_step2( $errors = false ) { echo '' . __( 'Caution:' ) . ' '; printf( /* translators: 1: wp-config.php, 2: .htaccess */ - __( 'You should back up your existing %1$s and %2$s files.' ), + __( 'We recommend you back up your existing %1$s and %2$s files.' ), 'wp-config.php', '.htaccess' ); @@ -452,7 +455,7 @@ function network_step2( $errors = false ) { echo '' . __( 'Caution:' ) . ' '; printf( /* translators: 1: wp-config.php, 2: web.config */ - __( 'You should back up your existing %1$s and %2$s files.' ), + __( 'We recommend you back up your existing %1$s and %2$s files.' ), 'wp-config.php', 'web.config' ); @@ -460,7 +463,7 @@ function network_step2( $errors = false ) { echo '' . __( 'Caution:' ) . ' '; printf( /* translators: %s: wp-config.php */ - __( 'You should back up your existing %s file.' ), + __( 'We recommend you back up your existing %s file.' ), 'wp-config.php' ); } diff --git a/src/wp-content/themes/twentynineteen/package-lock.json b/src/wp-content/themes/twentynineteen/package-lock.json index 11640ee6af05f..250082430e9aa 100644 --- a/src/wp-content/themes/twentynineteen/package-lock.json +++ b/src/wp-content/themes/twentynineteen/package-lock.json @@ -1553,7 +1553,8 @@ }, "nanoid": { "version": "3.1.30", - "resolved": "", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.30.tgz", + "integrity": "sha512-zJpuPDwOv8D2zq2WRoMe1HsfZthVewpel9CAvTfc/2mBD1uUT/agc5f7GHGWXlYkFvi1mVxe4IjvP2HNrop7nQ==", "dev": true }, "nice-try": { @@ -1997,7 +1998,8 @@ "dependencies": { "ansi-regex": { "version": "5.0.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, "ansi-styles": { @@ -2236,9 +2238,9 @@ "dev": true }, "qs": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", - "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", + "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==", "dev": true }, "queue-microtask": { diff --git a/src/wp-includes/ms-settings.php b/src/wp-includes/ms-settings.php index 6824895880f8b..1df500afa8968 100644 --- a/src/wp-includes/ms-settings.php +++ b/src/wp-includes/ms-settings.php @@ -54,15 +54,23 @@ // have not been populated in the global scope through something like `sunrise.php`. if ( ! isset( $current_site ) || ! isset( $current_blog ) ) { - $domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) ); - if ( ':80' === substr( $domain, -3 ) ) { - $domain = substr( $domain, 0, -3 ); - $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 ); - } elseif ( ':443' === substr( $domain, -4 ) ) { - $domain = substr( $domain, 0, -4 ); - $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 ); + /** + * Filters allowed HTTP ports in Multisite. + * + * @since 6.0.0 + * @param array $allowed_ports The allowed ports. Default is [ ':80', ':443' ]. + */ + $allowed_ports = apply_filters( 'allowed_multisite_ports', array( ':80', ':443' ) ); + + if ( is_array( $allowed_ports ) ) { + foreach ( $allowed_ports as $allowed_port ) { + $str_length = strlen( $allowed_port ); + if ( str_ends_with( $domain, $allowed_port ) ) { + $domain = substr( $domain, 0, - $str_length ); + $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, - $str_length ); + } + } } - $path = stripslashes( $_SERVER['REQUEST_URI'] ); if ( is_admin() ) { $path = preg_replace( '#(.*)/wp-admin/.*#', '$1/', $path ); diff --git a/src/wp-includes/ms-site.php b/src/wp-includes/ms-site.php index cdce8ff03381a..ed94bc95d83c5 100644 --- a/src/wp-includes/ms-site.php +++ b/src/wp-includes/ms-site.php @@ -503,7 +503,17 @@ function wp_normalize_site_data( $data ) { // Sanitize domain if passed. if ( array_key_exists( 'domain', $data ) ) { $data['domain'] = trim( $data['domain'] ); + $has_ports = strstr( $data['domain'], ':' ); + + // Remove ports. + $data['domain'] = preg_replace( '|:\d+$|', '', $data['domain'] ); $data['domain'] = preg_replace( '/\s+/', '', sanitize_user( $data['domain'], true ) ); + /** This filter is documented in wp-includes/ms-settings.php */ + $allowed_ports = apply_filters( 'allowed_multisite_ports', array( ':80', ':443' ) ); + if ( ( false !== $has_ports && is_array( $allowed_ports ) && in_array( $has_ports, $allowed_ports, true ) ) ) { + $data['domain'] .= $has_ports; + } + if ( is_subdomain_install() ) { $data['domain'] = str_replace( '@', '', $data['domain'] ); } diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index e2d4d78ddb98b..b25f54dbaee41 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -1603,6 +1603,12 @@ public function action_wp_validate_site_deletion_prevent_deletion( $errors ) { * @dataProvider data_wp_normalize_site_data */ public function test_wp_normalize_site_data( $data, $expected ) { + add_filter( + 'allowed_multisite_ports', + function( $ports ) { + return array( ':80', ':443', ':8080' ); + } + ); $result = wp_normalize_site_data( $data ); $this->assertSameSetsWithIndex( $expected, $result ); @@ -1674,6 +1680,30 @@ public function data_wp_normalize_site_data() { ), array(), ), + array( + array( + 'domain' => 'domainwithport.com:443', + ), + array( + 'domain' => 'domainwithport.com:443', + ), + ), + array( + array( + 'domain' => 'anotherdomainwithport.com:80', + ), + array( + 'domain' => 'anotherdomainwithport.com:80', + ), + ), + array( + array( + 'domain' => 'anotherwithport.com:8080', + ), + array( + 'domain' => 'anotherwithport.com:8080', + ), + ), ); }