Opened 4 years ago
Last modified 7 weeks ago
#55488 new enhancement
Add a filter to array of allow ported number in multisite.
| Reported by: | spacedmonkey | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Networks and Sites | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | multisite |
Description
The allowed port numbers to setup a multisite are fixed. See this line.
if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ), true ) ) ) {
However, a site maintainer may want to change these values to help enable serving their multisite from a custom port.
This ticket is a breakout from #21077
Change History (3)
This ticket was mentioned in PR #12728 on WordPress/wordpress-develop by @irozum.
7 weeks ago
#3
- Keywords has-patch has-unit-tests added; needs-patch removed
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.
## 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 ticket was mentioned in PR #12728 on WordPress/wordpress-develop by @irozum.
7 weeks ago
#2
- Keywords has-patch has-unit-tests added; needs-patch removed
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.
## 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
The code referenced in the description no longer exists. The
$has_portscheck within_array( $has_ports, array( ':80', ':443' ), true )has been refactored out of core.The underlying limitation is still present, though. The ports
:80and:443remain hardcoded in two places, with no filter to allow custom ports:wp-admin/includes/network.php(network setup):$hostname = preg_replace( '/(?::80|:443)$/', '', get_clean_basedomain() );wp-includes/ms-settings.php(bootstrap):So the enhancement is still valid, but the description should be updated to point at these two locations. A filter would need to cover both to keep setup and bootstrap consistent.