Skip to content

t530: fix orphan pending_site after membership cancellation#910

Merged
superdav42 merged 1 commit intomainfrom
feature/auto-20260422-134423-gh902
Apr 22, 2026
Merged

t530: fix orphan pending_site after membership cancellation#910
superdav42 merged 1 commit intomainfrom
feature/auto-20260422-134423-gh902

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

When a membership transitions to cancelled (e.g. the watchdog timeout), the pending_site stored in wu_membershipmeta was never cleaned up. If the customer retried checkout successfully, no code reclaimed the orphaned pending_site — the customer paid and received no site.

This PR adds handle_pending_site_on_cancellation() to Membership_Manager which hooks into the existing wu_transition_membership_status action and:

  1. Detects a pending_site on the cancelled membership
  2. Saves it to a 24h WordPress transient keyed by wu_transferable_pending_ + md5($email), making it reclaimable by a retry checkout flow
  3. Calls delete_pending_site() to remove the orphaned meta from the membership

Files Changed

  • EDIT inc/managers/class-membership-manager.php — new handle_pending_site_on_cancellation() method + hook registration in init()
  • EDIT tests/WP_Ultimo/Managers/Membership_Manager_Test.php — 5 new tests covering hook registration, pending_site cleanup, transient creation, no-op when no pending_site, and non-cancelled status bypass

Verification

OK (5 tests, 8 assertions)

PHPStan: No errors

Resolves #902

When a membership transitions to cancelled, the pending_site stored
in membership meta is no longer silently orphaned. The new
handle_pending_site_on_cancellation() handler in Membership_Manager:

1. Detects a pending_site on the cancelled membership
2. Saves it to a 24h transient keyed by customer email hash
   (wu_transferable_pending_ . md5($email)) for retry reclaim
3. Deletes the pending_site meta from the membership

Fixes the production incident where a customer paid via WC order
with a 100% coupon and received no site because the watchdog
auto-cancel had already orphaned the pending_site (Membership 479).

Resolves #902
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 27 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 4 minutes and 27 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2ca1162c-7bac-458d-8385-295242e9e9dc

📥 Commits

Reviewing files that changed from the base of the PR and between 25414b6 and 2069856.

📒 Files selected for processing (2)
  • inc/managers/class-membership-manager.php
  • tests/WP_Ultimo/Managers/Membership_Manager_Test.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-20260422-134423-gh902

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.

@superdav42
Copy link
Copy Markdown
Collaborator Author

Merge Summary

Issue: #902 — fix: orphan pending_site after membership cancellation — site never provisioned

Root cause: When a membership was cancelled (e.g. by the ~2s watchdog timeout), the pending_site stored in wu_membershipmeta was silently orphaned. A successful retry checkout had no way to reclaim it.

Fix: Added handle_pending_site_on_cancellation() to Membership_Manager, registered on wu_transition_membership_status. On cancellation:

  1. Retrieves pending_site from membership meta
  2. Stores it in a 24h transient keyed by wu_transferable_pending_ + md5($customer_email)
  3. Deletes the meta from the membership

Tests: 5 new unit tests in Membership_Manager_Test — all pass (PHPUnit 9.6.34, WP Multisite). PHPStan clean.

Files changed:

  • inc/managers/class-membership-manager.php (+56 lines)
  • tests/WP_Ultimo/Managers/Membership_Manager_Test.php (+124 lines)

@superdav42 superdav42 merged commit 060e07f into main Apr 22, 2026
11 checks passed
@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 4dc261a 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 39 (-2 / -5% ) 37.73 MB 860.50 ms 184.00 ms (+17.00 ms / +9% ) 1086.00 ms 2104.00 ms (+84.00 ms / +4% ) 2016.60 ms (+88.65 ms / +4% ) 88.05 ms (-4.00 ms / -5% )
1 56 49.03 MB 1000.00 ms (+43.00 ms / +4% ) 156.00 ms 1158.50 ms (+46.50 ms / +4% ) 2174.00 ms 2090.25 ms 80.60 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: orphan pending_site after membership cancellation — site never provisioned

1 participant