fix(memberships): skip team-owned memberships in transfer_membership#314
fix(memberships): skip team-owned memberships in transfer_membership#314
Conversation
`Woocommerce_Membership_Updated::transfer_membership()` rewrites `post_author` on the user_membership to reassign ownership. For team-owned memberships (those with a `_team_id` meta), that's insufficient: true ownership lives on the team post's `_member_id`, the linked subscription's `_customer_user`, and team_member user meta. Rewriting only `post_author` silently desyncs those and can trigger duplicate-team creation on the next renewal dispatch. Skip the transfer (with a log note) when the membership carries `_team_id`. Team ownership transfers must be handled at the team level, not via the user_membership post. Refs NPPM-2741. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Guards Woocommerce_Membership_Updated::transfer_membership() against corrupting SkyVerge Teams “team-owned” memberships by skipping transfers when a _team_id meta is present, and adds a unit test to cover the new behavior.
Changes:
- Detects
_team_idon an existing managed membership during transfer handling and exits early with a debug log instead of rewritingpost_author. - Adds a unit test ensuring
post_authorremains unchanged for team-owned memberships.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
includes/incoming-events/class-woocommerce-membership-updated.php |
Adds a guard to skip transferring team-owned memberships (identified by _team_id) and logs the skip to avoid ownership desync. |
tests/unit-tests/test-membership-transfer.php |
Adds a unit test verifying team-owned memberships are not transferred via post_author rewrite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey @adekbadek, good job getting this PR merged! 🎉 Now, the Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label. If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label. Thank you! ❤️ |
## [2.20.1-alpha.1](v2.20.0...v2.20.1-alpha.1) (2026-05-07) ### Bug Fixes * **memberships:** skip team-owned memberships in transfer_membership ([#314](#314)) ([9f9d2aa](9f9d2aa))
|
🎉 This PR is included in version 2.20.1-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Changes proposed in this Pull Request:
Refs NPPM-2741.
Woocommerce_Membership_Updated::transfer_membership()currently reassigns a user_membership to its new owner by rewritingpost_authorviawp_update_post. That's fine for standalone memberships, but for team-owned memberships (those with a_team_idmeta) ownership doesn't live onpost_author– it lives on three separate records:_member_id(the team owner)_customer_userRewriting only
post_authorsilently desyncs all of those. On the next renewal dispatch, SkyVerge Teams' owner-vs-customer check can then spawn a duplicate team, and the original team/membership pair gets orphaned.Today this path is hard to hit because SkyVerge Teams does not fire
wc_memberships_user_membership_transferred, soEvents::membership_transferrednever dispatches the network event for team memberships from the node side. But a future Teams version, a manual dispatch, a mis-linked remote membership, or a reconciliation flow could all reachtransfer_membershipwith a team-owned local membership, and today that would silently corrupt the data. This PR makes the function skip team-owned memberships and log a note instead.Cheapest guard:
get_post_meta( $existing_membership_id, '_team_id', true )– direct meta read, no object instantiation.How to test the changes in this Pull Request:
Unit tests – a new test
test_transfer_skips_team_owned_membershipis added alongside the existingTestMembershipTransfersuite. It sets up a managed user_membership with_team_id=42meta, invokestransfer_membership()via Reflection, and assertspost_authoris unchanged.Expected:
OK (5 tests, 7 assertions).Other information:
test_transfer_skips_team_owned_membership)🤖 Generated with Claude Code