fix(domain): skip auto domain-record creation when site uses a checkout-form base domain#1300
Conversation
…ut-form base domain
In subdirectory multisite, an operator can publish alternate base domains
via the checkout form's site_url field (available_domains /
available_domains_multi). When customers register subsites under that
alternate base — e.g. example.com/<slug> on a network whose primary host
is wp.example.test — the previous check in Domain_Manager:
$has_subdomain = str_replace($current_site->domain, '', $site->domain);
treated the alternate base as a per-subsite custom mapping and produced a
`primary_domain = true` Domain record for the shared base against every
newly registered subsite. That mapping then made Mercator/sunrise route
ALL `<base>/*` traffic to the single subsite owning that row and 404
every sibling.
This change introduces Domain_Manager::is_network_base_domain() which
recognises both the network primary AND any operator-configured
checkout-form base domain, and uses it in handle_site_created() and
handle_site_deleted() instead of the simple string test. Also adds two
extension seams:
- wu_should_create_domain_record_for_site (bool, \WP_Site)
Suppresses the automatic Domain record from addons/integrations.
- wu_checkout_form_base_domains (string[])
Lets integrations declare extra network-base hosts (e.g. hosts
provisioned by a host provider) so they are also excluded.
Includes regression tests in Domain_Manager_Test covering:
- is_network_base_domain matches the network primary
- case/www/scheme normalisation
- filter-injected base domains are honoured
- handle_site_created creates no Domain row for a checkout-form base
- wu_should_create_domain_record_for_site short-circuits creation
- handle_site_deleted enqueues no wu_remove_subdomain for a base
- normalize_base_domain handles scheme/path/port/case/www inputs
|
Warning Review limit reached
More reviews will be available in 18 minutes and 56 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
SummaryIn subdirectory multisite, an operator can publish an alternate base $has_subdomain = str_replace($current_site->domain, '', $site->domain);treated the alternate base as a per-subsite custom mapping and produced a Reproduction (matches the customer report)
FixIntroduce
Files changed
Behaviour delta
Verificationcd /home/dave/Git/ultimate-multisite--checkout-available-domains-auto-mapping
vendor/bin/phpcs inc/managers/class-domain-manager.php tests/WP_Ultimo/Managers/Domain_Manager_Test.php # ✅ 0 errors on new code
vendor/bin/phpstan analyse # ✅ pre-commit hook: 0 errors
vendor/bin/phpunit --filter 'Domain_Manager_Test' --no-coverage # ✅ 145 tests, 337 assertionsThe 8 new tests:
Related history
Merged via PR #1300 to main. aidevops.sh v3.20.1 spent 1m on this as a headless bash routine. |
Summary
In subdirectory multisite, an operator can publish an alternate base
domain via the checkout form's Site URL field (
available_domains/available_domains_multi). When customers register subsites under thatalternate base — for example
example.com/<slug>on a network whoseprimary host is
wp.example.test— the previous check inDomain_Manager::handle_site_created():treated the alternate base as a per-subsite custom mapping and produced a
primary_domain = trueDomain record for the shared base against everynewly registered subsite. That row then caused Mercator/sunrise to route
all
<base>/*traffic to the single subsite owning the mapping and404 every sibling subsite — until the operator manually deleted the row
from Ultimate Multisite → Domains.
Reproduction (matches the customer report)
wp.example.test.= on and Available Domains =
example.com.example.com→ siteexample.com/tenant.example.com(mappedto the new subsite,
primary_domain = true,stage = checking-dns)has been created automatically.
example.com/...→ Page not found.Fix
Introduce
Domain_Manager::is_network_base_domain($domain), whichrecognises both the network primary and any operator-configured
checkout-form base domain. Use it in
handle_site_created()andhandle_site_deleted()instead of the simple string test.Two extension seams are added for addons/integrations:
wu_should_create_domain_record_for_site(bool,\WP_Site) —return
falseto suppress the automatic Domain record from anywhere.wu_checkout_form_base_domains(string[]) — declare extranetwork-base hosts (e.g. hosts provisioned by a host-provider
integration) so they are also excluded from auto-mapping.
The DB scan that walks every published checkout form's
site_urlfieldis memoised per request, but the
wu_checkout_form_base_domainsfilteris re-applied on every call so addons (and tests) can override the list
without restarting the request.
Files changed
inc/managers/class-domain-manager.php— new helpersis_network_base_domain(),get_checkout_form_base_domains(),collect_checkout_form_base_domains(),normalize_base_domain();handle_site_created()andhandle_site_deleted()now use them andexpose the new filters.
tests/WP_Ultimo/Managers/Domain_Manager_Test.php— 8 new regressiontests (see below).
Behaviour delta
tenant.network.test(real subdomain) on a network rooted atnetwork.testnetwork.test/tenant(network primary)example.com/tenanton a network rooted atwp.example.testwithexample.comlisted in checkout formavailable_domainscustomer-brand.com(real per-site mapping, not in any checkout form)The change is strictly additive: hosts not listed in any checkout form
and not equal to the network primary still produce a mapped-domain
record exactly as before.
Verification
The 8 new tests:
test_is_network_base_domain_matches_network_primarytest_is_network_base_domain_normalises_host(case,www.)test_is_network_base_domain_rejects_unknown_hosttest_is_network_base_domain_honours_filtertest_handle_site_created_skips_domain_record_for_checkout_form_base(regression)test_handle_site_created_respects_should_create_filtertest_handle_site_deleted_skips_remove_for_checkout_form_base(regression)test_normalize_base_domain_handles_varied_inputsTwo failures observed in
Signup_Field_Site_Url_Test::test_to_fields_array_with_domain_selectionand
Site_Manager_Test::test_site_network_idreproduce identically onmain(commit1511f868) and are unrelated to this PR.Related history
793057d2— fix(checkout): use available_domains for auto-generated site URLs (fix(checkout): use available_domains for auto-generated site URLs #1072)41ea2f23— fix: site provisioning hardening — limitations, membership inference, domain promotion (fix: site provisioning hardening — limitations, membership inference, domain promotion #965)702e0c58— fix: auto-promote custom domain to primary on DNS verification (fix: auto-promote custom domain to primary on DNS verification for 3-part domains #991)#1072madeavailable_domainsactually flow into the new site'sdomaincolumn (good); this PR closes the matching gap on theDomain_Managerside so the alternate base is recognised as a sharednetwork base, not a per-site mapping.