Skip to content

fix: make sovereign tenant checks filterable#1274

Merged
superdav42 merged 1 commit into
mainfrom
fix/sovereign-tenant-filter
May 26, 2026
Merged

fix: make sovereign tenant checks filterable#1274
superdav42 merged 1 commit into
mainfrom
fix/sovereign-tenant-filter

Conversation

@superdav42

@superdav42 superdav42 commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add wu_is_sovereign_tenant() with the wu_is_sovereign_tenant filter so addons can opt core flows into sovereign-tenant behaviour.
  • Replace direct WU_MT_SOVEREIGN_TENANT checks across checkout, gateway, compat, and UI code with the helper.
  • Update sovereign-mode tests to enable the context via the filter instead of defining an addon-owned constant.

Verification

  • Pre-commit hook passed: PHPCS + PHPStan for staged PHP files.
  • vendor/bin/phpunit --filter Sovereign_Mode_Elements_Test --no-coverage
  • vendor/bin/phpunit --filter test_cart_constructor_sets_error_in_sovereign_context --no-coverage

Note: one parallel PHPUnit attempt hit the shared WP test DB setup race (network already exists); both targeted tests passed when run sequentially.


Summary by CodeRabbit

  • Tests

    • Updated test suite to reflect refactored tenant detection method
  • Chores

    • Refactored internal tenant detection across multiple system components to use a unified helper function

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8f3c7768-76f6-4f1c-822c-edb7d9a15fe3

📥 Commits

Reviewing files that changed from the base of the PR and between c5b5ef4 and bd0f93d.

📒 Files selected for processing (20)
  • inc/checkout/class-cart.php
  • inc/checkout/class-checkout-pages.php
  • inc/checkout/class-checkout.php
  • inc/class-wp-ultimo.php
  • inc/compat/class-auto-delete-users-compat.php
  • inc/compat/class-edit-users-compat.php
  • inc/compat/class-multiple-accounts-compat.php
  • inc/functions/sovereign.php
  • inc/managers/class-gateway-manager.php
  • inc/ui/class-account-summary-element.php
  • inc/ui/class-billing-info-element.php
  • inc/ui/class-checkout-element.php
  • inc/ui/class-current-membership-element.php
  • inc/ui/class-current-site-element.php
  • inc/ui/class-domain-mapping-element.php
  • inc/ui/class-invoices-element.php
  • inc/ui/class-my-sites-element.php
  • inc/ui/class-template-switching-element.php
  • tests/WP_Ultimo/Checkout/Checkout_Test.php
  • tests/WP_Ultimo/UI/Sovereign_Mode_Elements_Test.php

📝 Walkthrough

Walkthrough

This PR refactors sovereign-tenant detection by introducing a filter-based helper function wu_is_sovereign_tenant() to replace all direct WU_MT_SOVEREIGN_TENANT constant checks. The function is registered as a public API and deployed across checkout, UI elements, compatibility classes, and gateway logic, with corresponding test infrastructure changes to enable filter-based testing.

Changes

Sovereign Tenant Filter-Based Detection

Layer / File(s) Summary
Filter helper definition and public API registration
inc/functions/sovereign.php, inc/class-wp-ultimo.php
wu_is_sovereign_tenant() helper function wraps the wu_is_sovereign_tenant WordPress filter, defaulting to false. Function is loaded as a public API during plugin initialization alongside other globally-available helpers.
Checkout and order handling sovereign detection
inc/checkout/class-cart.php, inc/checkout/class-checkout.php, inc/checkout/class-checkout-pages.php
Cart constructor, all four AJAX handlers (order submission, creation, user existence, inline login), and URL redirection filters now use wu_is_sovereign_tenant() instead of constant checks. Cart initialization sets sovereign_checkout_disabled error for sovereign context. Checkout_Pages clears unused email-rewrite parameters via unset().
UI element sovereign-tenant rendering
inc/ui/class-account-summary-element.php, inc/ui/class-billing-info-element.php, inc/ui/class-checkout-element.php, inc/ui/class-current-membership-element.php, inc/ui/class-current-site-element.php, inc/ui/class-domain-mapping-element.php, inc/ui/class-invoices-element.php, inc/ui/class-my-sites-element.php, inc/ui/class-template-switching-element.php
Nine UI element classes updated to detect sovereign tenants via wu_is_sovereign_tenant() before rendering elements/sovereign-redirect templates. Same redirect-template rendering and early-return behavior preserved; only condition predicate changed.
Compatibility and gateway sovereign detection
inc/compat/class-auto-delete-users-compat.php, inc/compat/class-edit-users-compat.php, inc/compat/class-multiple-accounts-compat.php, inc/managers/class-gateway-manager.php
Compatibility class init() methods and gateway payment confirmation/status-check methods now return early when wu_is_sovereign_tenant() is true, replacing prior constant checks. No other control flow changes.
Test suite filter-based sovereign context
tests/WP_Ultimo/Checkout/Checkout_Test.php, tests/WP_Ultimo/UI/Sovereign_Mode_Elements_Test.php
Tests refactored to enable sovereign behavior via wu_is_sovereign_tenant filter in setUp() and cleanup in tearDown(), removing prior constant definitions. Helper methods (return_true() callback and filter registration) introduced to isolate sovereign-mode testing. Cart constructor test asserts filter returns true before verifying error state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

review-feedback-scanned, origin:worker, adr-001

Poem

🐰 Constants fade to filters bright,
Sovereign checks now done right,
Tests dance freely with no chains,
Helper guards our sovereign reigns,
A cleaner path through tenant lands!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: introducing a filterable sovereign tenant check via a new helper function instead of direct constant checks.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sovereign-tenant-filter

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

@github-actions

Copy link
Copy Markdown

Performance Test Results

Performance test results for f2017d6 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 40 37.78 MB 906.50 ms (+63.00 ms / +7% ) 152.50 ms (-18.00 ms / -12% ) 1054.50 ms (+33.50 ms / +3% ) 2014.00 ms 1929.65 ms 77.25 ms
1 56 49.13 MB 952.50 ms (+21.00 ms / +2% ) 139.50 ms 1092.00 ms 2090.00 ms 2018.75 ms 72.00 ms

@superdav42 superdav42 merged commit 0e139f6 into main May 26, 2026
11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

Summary

  • Add wu_is_sovereign_tenant() with the wu_is_sovereign_tenant filter so addons can opt core flows into sovereign-tenant behaviour.
  • Replace direct WU_MT_SOVEREIGN_TENANT checks across checkout, gateway, compat, and UI code with the helper.
  • Update sovereign-mode tests to enable the context via the filter instead of defining an addon-owned constant.

Verification

  • Pre-commit hook passed: PHPCS + PHPStan for staged PHP files.
  • vendor/bin/phpunit --filter Sovereign_Mode_Elements_Test --no-coverage
  • vendor/bin/phpunit --filter test_cart_constructor_sets_error_in_sovereign_context --no-coverage
    Note: one parallel PHPUnit attempt hit the shared WP test DB setup race (network already exists); both targeted tests passed when run sequentially.


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


aidevops.sh v3.19.1 spent 36s on this as a headless bash routine.

@superdav42 superdav42 added the review-feedback-scanned Merged PR already scanned for quality feedback label May 26, 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