Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/wp-admin/includes/network.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ function network_step1( $errors = false ) {
}

// Strip standard port from hostname.
$hostname = preg_replace( '/(?::80|:443)$/', '', get_clean_basedomain() );
$port_pattern = '/(?:' . implode( '|', array_map( 'preg_quote', ms_default_port_suffixes() ) ) . ')$/';
$hostname = preg_replace( $port_pattern, '', get_clean_basedomain() );
Comment on lines 152 to +154

echo '<form method="post">';

Expand Down
22 changes: 22 additions & 0 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,28 @@ function is_serialized_string( $data ) {
}
}

/**
* Retrieves the port suffixes considered "default" for a Multisite domain.
*
* These port suffixes are stripped from a hostname during the Multisite
* bootstrap process, and used to suggest a default network hostname when
* setting up a new network.
*
* @since 7.2.0
*
* @return string[] Array of default port suffixes, e.g. array( ':80', ':443' ).
*/
function ms_default_port_suffixes() {
/**
* Filters the port suffixes considered "default" for a Multisite domain.
*
* @since 7.2.0
*
* @param string[] $port_suffixes Array of default port suffixes, e.g. array( ':80', ':443' ).
*/
return apply_filters( 'ms_default_port_suffixes', array( ':80', ':443' ) );
}
Comment on lines +762 to +782

/**
* Retrieves post title from XML-RPC XML.
*
Expand Down
12 changes: 6 additions & 6 deletions src/wp-includes/ms-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
if ( ! isset( $current_site ) || ! isset( $current_blog ) ) {

$domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ?? '' ) );
if ( str_ends_with( $domain, ':80' ) ) {
$domain = substr( $domain, 0, -3 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 );
} elseif ( str_ends_with( $domain, ':443' ) ) {
$domain = substr( $domain, 0, -4 );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 );
foreach ( ms_default_port_suffixes() as $port_suffix ) {
if ( str_ends_with( $domain, $port_suffix ) ) {
$domain = substr( $domain, 0, -strlen( $port_suffix ) );
$_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -strlen( $port_suffix ) );
break;
}
}

$path = stripslashes( $_SERVER['REQUEST_URI'] );
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/tests/functions/msDefaultPortSuffixes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Tests for the ms_default_port_suffixes() function.
*
* @group functions
* @group multisite
*
* @covers ::ms_default_port_suffixes
*/
class Tests_Functions_MsDefaultPortSuffixes extends WP_UnitTestCase {

/**
* @ticket 55488
*/
public function test_returns_standard_ports_by_default() {
$this->assertSame( array( ':80', ':443' ), ms_default_port_suffixes() );
}

/**
* @ticket 55488
*/
public function test_result_is_filterable() {
add_filter( 'ms_default_port_suffixes', array( $this, 'filter_port_suffixes' ) );

$this->assertSame( array( ':8080' ), ms_default_port_suffixes() );
}

public function filter_port_suffixes() {
return array( ':8080' );
}
Comment on lines +29 to +31
}
Loading