Skip to content

fix(domain): skip auto domain-record creation when site uses a checkout-form base domain#1300

Merged
superdav42 merged 1 commit into
mainfrom
fix/checkout-available-domains-auto-mapping
May 28, 2026
Merged

fix(domain): skip auto domain-record creation when site uses a checkout-form base domain#1300
superdav42 merged 1 commit into
mainfrom
fix/checkout-available-domains-auto-mapping

Conversation

@superdav42

Copy link
Copy Markdown
Collaborator

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 that
alternate base — for example example.com/<slug> on a network whose
primary host is wp.example.test — the previous check in
Domain_Manager::handle_site_created():

$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 row then caused Mercator/sunrise to route
all <base>/* traffic to the single subsite owning the mapping and
404 every sibling subsite — until the operator manually deleted the row
from Ultimate Multisite → Domains.

Reproduction (matches the customer report)

  1. Subdirectory multisite installed on wp.example.test.
  2. In the checkout form's Site URL field, set Enable Domain Selection
    = on
    and Available Domains = example.com.
  3. Customer registers, selecting example.com → site example.com/tenant.
  4. Open Ultimate Multisite → Domains: a row for example.com (mapped
    to the new subsite, primary_domain = true, stage = checking-dns)
    has been created automatically.
  5. Visit any other subsite under example.com/...Page not found.
  6. Delete the row → all subsites resolve again.

Fix

Introduce Domain_Manager::is_network_base_domain($domain), which
recognises both the network primary and any operator-configured
checkout-form base domain. Use it in handle_site_created() and
handle_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 false to suppress the automatic Domain record from anywhere.
  • wu_checkout_form_base_domains (string[]) — declare extra
    network-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_url field
is memoised per request, but the wu_checkout_form_base_domains filter
is 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 helpers
    is_network_base_domain(), get_checkout_form_base_domains(),
    collect_checkout_form_base_domains(), normalize_base_domain();
    handle_site_created() and handle_site_deleted() now use them and
    expose the new filters.
  • tests/WP_Ultimo/Managers/Domain_Manager_Test.php — 8 new regression
    tests (see below).

Behaviour delta

Scenario Before After
Subsite at tenant.network.test (real subdomain) on a network rooted at network.test Domain record auto-created unchanged — still auto-created
Subsite at network.test/tenant (network primary) Skipped unchanged — still skipped
Subsite at example.com/tenant on a network rooted at wp.example.test with example.com listed in checkout form available_domains Domain record auto-created → breaks siblings Skipped — siblings keep working
Subsite at customer-brand.com (real per-site mapping, not in any checkout form) Domain record auto-created unchanged — still auto-created

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

cd /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 assertions

The 8 new tests:

  • test_is_network_base_domain_matches_network_primary
  • test_is_network_base_domain_normalises_host (case, www.)
  • test_is_network_base_domain_rejects_unknown_host
  • test_is_network_base_domain_honours_filter
  • test_handle_site_created_skips_domain_record_for_checkout_form_base (regression)
  • test_handle_site_created_respects_should_create_filter
  • test_handle_site_deleted_skips_remove_for_checkout_form_base (regression)
  • test_normalize_base_domain_handles_varied_inputs

Two failures observed in Signup_Field_Site_Url_Test::test_to_fields_array_with_domain_selection
and Site_Manager_Test::test_site_network_id reproduce identically on
main
(commit 1511f868) and are unrelated to this PR.

Related history

#1072 made available_domains actually flow into the new site's
domain column (good); this PR closes the matching gap on the
Domain_Manager side so the alternate base is recognised as a shared
network base, not a per-site mapping.


…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
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@superdav42, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e42b4ebf-48e1-4b4b-a731-e7ac873ffae0

📥 Commits

Reviewing files that changed from the base of the PR and between 1511f86 and 8b33813.

📒 Files selected for processing (2)
  • inc/managers/class-domain-manager.php
  • tests/WP_Ultimo/Managers/Domain_Manager_Test.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/checkout-available-domains-auto-mapping

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

🔨 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!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42 superdav42 merged commit 7bd8342 into main May 28, 2026
8 of 11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

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 that
alternate base — for example example.com/<slug> on a network whose
primary host is wp.example.test — the previous check in
Domain_Manager::handle_site_created():

$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 row then caused Mercator/sunrise to route
all <base>/* traffic to the single subsite owning the mapping and
404 every sibling subsite — until the operator manually deleted the row
from Ultimate Multisite → Domains.

Reproduction (matches the customer report)

  1. Subdirectory multisite installed on wp.example.test.
  2. In the checkout form's Site URL field, set Enable Domain Selection
    = on
    and Available Domains = example.com.
  3. Customer registers, selecting example.com → site example.com/tenant.
  4. Open Ultimate Multisite → Domains: a row for example.com (mapped
    to the new subsite, primary_domain = true, stage = checking-dns)
    has been created automatically.
  5. Visit any other subsite under example.com/...Page not found.
  6. Delete the row → all subsites resolve again.

Fix

Introduce Domain_Manager::is_network_base_domain($domain), which
recognises both the network primary and any operator-configured
checkout-form base domain. Use it in handle_site_created() and
handle_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 false to suppress the automatic Domain record from anywhere.
  • wu_checkout_form_base_domains (string[]) — declare extra
    network-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_url field
    is memoised per request, but the wu_checkout_form_base_domains filter
    is 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 helpers
    is_network_base_domain(), get_checkout_form_base_domains(),
    collect_checkout_form_base_domains(), normalize_base_domain();
    handle_site_created() and handle_site_deleted() now use them and
    expose the new filters.
  • tests/WP_Ultimo/Managers/Domain_Manager_Test.php — 8 new regression
    tests (see below).

Behaviour delta

Scenario Before After
Subsite at tenant.network.test (real subdomain) on a network rooted at network.test Domain record auto-created unchanged — still auto-created
Subsite at network.test/tenant (network primary) Skipped unchanged — still skipped
Subsite at example.com/tenant on a network rooted at wp.example.test with example.com listed in checkout form available_domains Domain record auto-created → breaks siblings Skipped — siblings keep working
Subsite at customer-brand.com (real per-site mapping, not in any checkout form) Domain record auto-created unchanged — still auto-created
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

cd /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 assertions

The 8 new tests:

  • test_is_network_base_domain_matches_network_primary
  • test_is_network_base_domain_normalises_host (case, www.)
  • test_is_network_base_domain_rejects_unknown_host
  • test_is_network_base_domain_honours_filter
  • test_handle_site_created_skips_domain_record_for_checkout_form_base (regression)
  • test_handle_site_created_respects_should_create_filter
  • test_handle_site_deleted_skips_remove_for_checkout_form_base (regression)
  • test_normalize_base_domain_handles_varied_inputs
    Two failures observed in Signup_Field_Site_Url_Test::test_to_fields_array_with_domain_selection
    and Site_Manager_Test::test_site_network_id reproduce identically on
    main
    (commit 1511f868) and are unrelated to this PR.

Related history



Merged via PR #1300 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.20.1 spent 1m on this as a headless bash routine.

@superdav42 superdav42 added the review-feedback-scanned Merged PR already scanned for quality feedback label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant