Skip to content

fix: resolve magic link shortcode without site context#1594

Merged
superdav42 merged 2 commits into
mainfrom
fix/magic-link-main-site-fallback
Jun 30, 2026
Merged

fix: resolve magic link shortcode without site context#1594
superdav42 merged 2 commits into
mainfrom
fix/magic-link-main-site-fallback

Conversation

@superdav42

@superdav42 superdav42 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Resolve [wu_magic_link_url] on main-site pages when no site_id or ?site= context is present.
  • Fall back to the logged-in customer's primary customer-owned site, then the first eligible customer site.
  • Add regression coverage for explicit site IDs, ?site= hashes, customer primary-site fallback, non-customer primary blog fallback, and shortcode rendering.

Verification

  • vendor/bin/phpcs inc/ui/class-magic-link-url-element.php tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php
  • php -l inc/ui/class-magic-link-url-element.php
  • php -l tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php
  • git diff --check
  • Pre-commit hook: PHPCS and PHPStan passed for staged PHP file

Notes

  • vendor/bin/phpunit --filter Magic_Link_Url_Element_Test could not run locally because /tmp/wordpress-tests-lib/includes/functions.php is not installed in this environment.

Summary by CodeRabbit

  • Bug Fixes
    • Improved account link resolution so the correct site is used more reliably when no site is explicitly selected.
    • Added a fallback to the customer’s available sites, helping links continue to work even when the primary site is unavailable or not eligible.
    • Account buttons/links now more consistently point to the active site and display the expected destination.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6f2ecc0f-4c17-4919-9ed9-4eadf33e2ae9

📥 Commits

Reviewing files that changed from the base of the PR and between 8f77741 and f28f7e5.

📒 Files selected for processing (1)
  • tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php
📝 Walkthrough

Walkthrough

get_site_id_from_atts() in Magic_Link_Url_Element gains a fallback to a new get_current_customer_site_id() helper that selects the customer's primary or first valid customer_owned site. A new is_customer_site_candidate() validates type, ownership, and access. A full PHPUnit test class is added covering all resolution paths and shortcode rendering.

Changes

Magic Link URL customer site fallback

Layer / File(s) Summary
Customer site resolution helpers and fallback
inc/ui/class-magic-link-url-element.php
get_site_id_from_atts() now calls get_current_customer_site_id() instead of returning null on lookup failure. Two new helpers implement candidate iteration (preferring primary_blog) and validation (type customer_owned, ownership, is_customer_allowed()).
Unit tests
tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php
New test class with fixture setup/teardown, reflection-based invocation of the protected method, and assertions covering explicit site_id, request hash, primary blog fallback, non-customer-owned skipping, and shortcode output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hop, hop, who owns this site?
The customer's primary blog shines bright,
We check the type, we check the id,
is_customer_allowed() seals the bid.
No more null — we found the right!

🚥 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 clearly summarizes the main fix: resolving the magic link shortcode when site context is missing.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/magic-link-main-site-fallback

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.

@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

Copy link
Copy Markdown
Collaborator Author

MERGE_SUMMARY

Summary

  • Fixed the PR-only Magic_Link_Url_Element_Test fixture by setting $_SERVER['REMOTE_ADDR'] before self::factory()->blog->create() calls.
  • Restores the previous REMOTE_ADDR state in tearDown() to avoid leaking server globals across tests.
  • Pushed commit f28f7e54 to fix/magic-link-main-site-fallback.

Verification

  • gh run view 28419208103 --repo Ultimate-Multisite/ultimate-multisite --job 84208687960/84208687969/84208687961 logs showed the PHP 8.2/8.4/8.5 failures were five Undefined array key "REMOTE_ADDR" errors from tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php:52.
  • vendor/bin/phpcs tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php passed.
  • php -l tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php passed.
  • git diff --check HEAD~2 HEAD passed.
  • vendor/bin/phpunit --filter Magic_Link_Url_Element_Test passed: 5 tests, 7 assertions.

aidevops.sh v3.29.41 plugin for OpenCode v1.17.11

@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

Copy link
Copy Markdown
Collaborator Author

Remote CI follow-up: Unit & Integration Tests run 28439950972 completed successfully after commit f28f7e54.

Relevant checks:

  • PHP 8.2: success
  • PHP 8.3: success
  • PHP 8.4: success
  • PHP 8.5: success
  • PHP Lint: success
  • WP Performance Metrics: success

aidevops.sh v3.29.41 plugin for OpenCode v1.17.11

@superdav42 superdav42 merged commit 3e79498 into main Jun 30, 2026
11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

Summary

  • Resolve [wu_magic_link_url] on main-site pages when no site_id or ?site= context is present.
  • Fall back to the logged-in customer's primary customer-owned site, then the first eligible customer site.
  • Add regression coverage for explicit site IDs, ?site= hashes, customer primary-site fallback, non-customer primary blog fallback, and shortcode rendering.

Verification

  • vendor/bin/phpcs inc/ui/class-magic-link-url-element.php tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php
  • php -l inc/ui/class-magic-link-url-element.php
  • php -l tests/WP_Ultimo/UI/Magic_Link_Url_Element_Test.php
  • git diff --check
  • Pre-commit hook: PHPCS and PHPStan passed for staged PHP file

Notes

  • vendor/bin/phpunit --filter Magic_Link_Url_Element_Test could not run locally because /tmp/wordpress-tests-lib/includes/functions.php is not installed in this environment.


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


aidevops.sh v3.29.41 spent 12m on this as a headless bash routine.

@superdav42

Copy link
Copy Markdown
Collaborator Author

CLAIM_RELEASED reason=worker_complete runner=superdav42 ts=2026-06-30T11:27:41Z aidevops_version=3.29.41 opencode_version=1.17.11

@superdav42 superdav42 added status:available Task is available for claiming review-feedback-scanned Merged PR already scanned for quality feedback labels Jun 30, 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 status:available Task is available for claiming

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant