fix(content-gate): cascade taxonomy content rules to child terms (NPPD-1670)#283
Open
adekbadek wants to merge 2 commits into
Open
Conversation
…D-1670) Content gates with taxonomy-term content rules now include a targeted term's descendants for hierarchical taxonomies, matching the cascade behavior of WooCommerce Memberships. Previously a rule targeting a parent category did not gate posts assigned only to a child category, so restricted content could leak. Expansion happens at evaluation time via get_term_children(), so child terms added after a rule is saved are covered automatically. Symmetric for inclusion and exclusion rules; non-hierarchical taxonomies (tags) are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a content-gate evaluation gap where taxonomy-term rules didn’t cascade from a parent term to its descendants for hierarchical taxonomies (e.g., categories), which could allow restricted content to appear ungated on child-category posts. The change aligns Newspack’s behavior with WooCommerce Memberships by expanding hierarchical rule targets at evaluation time.
Changes:
- Expand hierarchical taxonomy rule term IDs to include descendant terms before evaluating post matches.
- Add unit tests covering inclusion cascade, exclusion cascade, one-directional behavior, and non-hierarchical taxonomy behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| plugins/newspack-plugin/includes/content-gate/class-content-restriction-control.php | Expands hierarchical taxonomy rule targets (via get_term_children()) before intersecting with a post’s assigned term IDs. |
| plugins/newspack-plugin/tests/unit-tests/content-gate/content-gates.php | Adds unit tests validating hierarchical descendant cascading and non-hierarchical passthrough behavior. |
…or-hierarchical-taxonomies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
Fixes NPPD-1670. Content gates with taxonomy-term content rules now cascade to a targeted term's child terms for hierarchical taxonomies (categories), matching WooCommerce Memberships.
Previously
Content_Restriction_Control::get_post_gates()matched a post's term IDs against a rule's term IDs with a flatarray_intersect, so a rule targeting a parent category did not gate posts assigned only to a child category. Restricted content leaked: a publisher reported no paywall appearing on child-category posts.The fix adds a private
expand_hierarchical_terms()helper that expands a hierarchical-taxonomy rule's target terms to include all descendants (viaget_term_children()) before the intersect. Key properties:newspack-managerconsumer is unaffected.How to test the changes in this Pull Request:
n test-php --filter test_content_rules(covers inclusion cascade, exclusion cascade, the one-directional guarantee, and non-hierarchical passthrough).Rollout note
Because expansion is evaluation-time, on deploy every existing gate targeting a parent category recomputes its gated-post set with no migration step — this is a behavior-changing deploy, not a transparent fix. A per-site audit of the currently-live Access-Control sites (which gates expand and by how much) is tracked on NPPD-1670.
Other information:
Test_Content_Gates: 56 tests / 167 assertions green; PHPCS clean.)