Networks and Sites: Add a filter for default Multisite port suffixes - #12728
Networks and Sites: Add a filter for default Multisite port suffixes#12728irozum wants to merge 4 commits into
Conversation
…ostname suggestion
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
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 inwp-includes/functions.phpwith a default ofarray( ':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.
| public function filter_port_suffixes() { | ||
| return array( ':8080' ); | ||
| } |
| /** | ||
| * 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' ) ); | ||
| } |
| // 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() ); |
Adds a
ms_default_port_suffixesfilter 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()inwp-includes/functions.php, which wraps the new filter and defaults toarray( ':80', ':443' )— the same values previously hardcoded. Both existing call sites now use it: the Multisite bootstrap domain normalization inwp-includes/ms-settings.php, and the default hostname suggestion inwp-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 anms-*file) becausewp-admin/includes/network.phpruns during the one-time "enable Multisite" step, before Multisite itself is active — soms-functions.php/ms-load.phparen't guaranteed loaded yet at that point, whilefunctions.phpalways is.Added
tests/phpunit/tests/functions/msDefaultPortSuffixes.php, covering the default return value and that it can be filtered. The existingTests_Multisite_Bootstrapsuite (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.