diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index f1b08567cd257..7669d33103fef 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -150,7 +150,7 @@ jobs: - name: Upload single site report to Codecov if: ${{ ! matrix.multisite }} - uses: codecov/codecov-action@e3c560433a6cc60aec8812599b7844a7b4fa0d71 # v3.0.0 + uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.0.0 with: file: wp-code-coverage-single-clover-${{ github.sha }}.xml flags: single,php @@ -164,7 +164,7 @@ jobs: - name: Upload multisite report to Codecov if: ${{ matrix.multisite }} - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v2.1.0 with: file: wp-code-coverage-multisite-clover-${{ github.sha }}.xml flags: multisite,php 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.' ) . '
' . 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-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',
+ ),
+ ),
);
}