Skip to content

fix(relationships): clean up post dependencies on permanent delete - #3264

Open
faisalahammad wants to merge 1 commit into
gocodebox:devfrom
faisalahammad:fix/263-post-trash-relationships
Open

fix(relationships): clean up post dependencies on permanent delete#3264
faisalahammad wants to merge 1 commit into
gocodebox:devfrom
faisalahammad:fix/263-post-trash-relationships

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Description

Cleans up stale cross-post references when LifterLMS posts are permanently deleted. Previously, deleting a course, section, lesson, or membership left behind prerequisite links, membership auto-enroll entries, restriction arrays, parent meta, and the sitewide membership option pointing at the deleted post.

Hooks into the existing delete_post flow in LLMS_Post_Relationships (same place access plans and quiz/question cleanup already run). Adds a remove_from_meta action for serialized array meta and a get_posts_with_meta_containing() helper with a LIKE pre-filter.

Cleanup paths added

Course deleted

  • Unset prerequisites on other courses that required it
  • Remove course ID from membership auto-enroll arrays
  • Force-delete child sections
  • Unset parent-course meta on lessons

Section deleted

  • Unset parent-section meta on lessons

Membership deleted

  • Remove membership ID from post restriction arrays (_llms_restricted_levels)
  • Remove membership ID from access plan availability restrictions (_llms_availability_restrictions)
  • Clear sitewide lifterlms_membership_required option when it matches

Out of scope (this PR)

  • Trash/untrash (wp_trash_post) — cleanup runs on permanent delete only, matching existing relationship handlers
  • Cancel enrollments
  • Track prerequisite cleanup
  • Builder empty-node warnings

How has this been tested?

  • New PHPUnit coverage in tests/phpunit/unit-tests/class-llms-test-post-relationships.php for each cleanup path
  • Manual verification checklist covers course/section/membership delete cases

Screenshots / Screencasts

N/A — backend relationship cleanup only.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code has been tested.
  • My code follows the WordPress/LifterLMS Coding Standards.
  • My code follows the above Contributor Guide.
  • My code includes any required tests that prove my fix is effective or that my feature works.
  • My changelog has been updated to reflect the nature of my contribution.
  • New files have the correct header and license information.
  • I have read the CONTRIBUTING document.
  • My code follows the WordPress Coding Standards.
  • My code is ready to be merged.

Fixes #263

- Add course prerequisite unset on other courses when course deleted
- Add course ID removal from membership auto-enroll arrays
- Add child section force-deletion when course is deleted
- Add lesson parent-course meta unset when course is deleted
- Add section parent-section meta unset on lessons when section deleted
- Add membership ID removal from post restriction arrays (_llms_restricted_levels)
- Add membership ID removal from access plan availability restrictions (_llms_availability_restrictions)
- Add sitewide membership option (lifterlms_membership_required) cleanup on membership deletion
- Add remove_from_meta action type for serialized array meta cleanup
- Add get_posts_with_meta_containing() helper using LIKE pre-filter
- Add unit test coverage for all new cleanup paths

Fixes gocodebox#263
@faisalahammad
faisalahammad requested a review from brianhogg as a code owner July 22, 2026 12:56
@brianhogg brianhogg moved this to Awaiting Review in Development Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting Review

Development

Successfully merging this pull request may close these issues.

2 participants