Skip to content

Networks and Sites: Add a filter for default Multisite port suffixes - #12728

Open
irozum wants to merge 4 commits into
WordPress:trunkfrom
irozum:enhancement/55488-allow-custom-multisite-port-filter
Open

Networks and Sites: Add a filter for default Multisite port suffixes#12728
irozum wants to merge 4 commits into
WordPress:trunkfrom
irozum:enhancement/55488-allow-custom-multisite-port-filter

Conversation

@irozum

@irozum irozum commented Jul 28, 2026

Copy link
Copy Markdown

Adds a ms_default_port_suffixes filter so site owners can customize which port suffixes are treated as "default" when Multisite bootstraps a request and when the Tools → Network Setup screen suggests a hostname, instead of the hardcoded :80/:443. Without this, a Multisite install served from a non-standard port (e.g. :8080) has no supported way to make that port behave like the standard ones during domain matching.

Introduces ms_default_port_suffixes() in wp-includes/functions.php, which wraps the new filter and defaults to array( ':80', ':443' ) — the same values previously hardcoded. Both existing call sites now use it: the Multisite bootstrap domain normalization in wp-includes/ms-settings.php, and the default hostname suggestion in wp-admin/includes/network.php's network setup wizard. Behavior is unchanged unless the new filter is used, since both call sites fall back to the same default port list.

The function is defined in wp-includes/functions.php (rather than an ms-* file) because wp-admin/includes/network.php runs during the one-time "enable Multisite" step, before Multisite itself is active — so ms-functions.php/ms-load.php aren't guaranteed loaded yet at that point, while functions.php always is.

Added tests/phpunit/tests/functions/msDefaultPortSuffixes.php, covering the default return value and that it can be filtered. The existing Tests_Multisite_Bootstrap suite (60 tests) continues to pass unchanged, confirming no regression to domain/network resolution.

Trac ticket: https://core.trac.wordpress.org/ticket/55488

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Implementation, tests, and PR description. Reviewed by Igor Rozum.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copilot AI review requested due to automatic review settings July 28, 2026 03:05
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props irozum.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new ms_default_port_suffixes filter (via ms_default_port_suffixes()) so Multisite can treat non-:80/:443 ports as “default” during bootstrap hostname normalization and when suggesting a hostname on the Network Setup screen.

Changes:

  • Introduces ms_default_port_suffixes() wrapper in wp-includes/functions.php with a default of array( ':80', ':443' ).
  • Updates Multisite bootstrap domain normalization (wp-includes/ms-settings.php) to strip any configured default port suffix.
  • Updates Network Setup hostname suggestion (wp-admin/includes/network.php) to use the filterable suffix list, and adds PHPUnit coverage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/phpunit/tests/functions/msDefaultPortSuffixes.php Adds tests for the new helper’s default value and filterability.
src/wp-includes/ms-settings.php Uses ms_default_port_suffixes() to strip configurable “default” ports during Multisite bootstrap.
src/wp-includes/functions.php Adds ms_default_port_suffixes() and the ms_default_port_suffixes filter.
src/wp-admin/includes/network.php Uses ms_default_port_suffixes() to strip configurable “default” ports when suggesting the hostname in Network Setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +31
public function filter_port_suffixes() {
return array( ':8080' );
}
Comment on lines +762 to +782
/**
* 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 152 to +154
// 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() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants