Skip to content

Conversation

@miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Oct 22, 2025

All Submissions:

Changes proposed in this Pull Request:

Depends on #4265

Implements the restriction rules as designed in #4265.

How to test the changes in this Pull Request:

  1. Deactivate Woo Memberships
  2. Create multiple gates, one for each available access and content rule (post type, category, and tag)
  3. Create a post that matches one of the gate content rules (tag or category)
  4. Use wp shell to execute Newspack\Content_Restriction_Control::get_post_gates( $post_id );
  5. Confirm you get the correct gates
  6. Edit the post to match other (multiple) gate rules
  7. Restart the shell and run Newspack\Content_Restriction_Control::get_post_gates( $post_id );
  8. Confirm you get the correct gates
  9. The rule evaluation logic wasn't changed, but the logic that implements it for restriction was. Edit a gate access rule to run behind a subscription
  10. As a reader without the subscription, confirm the gate renders in content restricted by it
  11. As a reader with the subscription, confirm you have access to the content

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

miguelpeixe and others added 30 commits September 19, 2025 16:19
* feat: add content gate settings skeleton

* fix: typescript

* fix: lint

* feat: read content gates data from array

* feat: render content gates from array

* feat: add content rules section

* fix: typescript errors

* fix: add missing module

* fix: typescript errors

* fix: add missing module

* fix: gate type

* fix: revert type declaration

---------

Co-authored-by: Rasmy Nguyen <[email protected]>
…to feat/content-gate-restriction-control--content-rules
…to feat/content-gate-restriction-control--content-rules
…to feat/content-gate-restriction-control--content-rules
@miguelpeixe miguelpeixe self-assigned this Dec 2, 2025
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Dec 2, 2025
@dkoo dkoo requested a review from Copilot December 2, 2025 18:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements restriction rules for content gates, refactoring the logic from metadata-based matching to a rule-based system. The changes enable more flexible content restriction by supporting multiple content rule types (post types, categories, tags) that must all match for a gate to apply to a post.

Key Changes:

  • Refactored get_post_gates() to evaluate content rules (post type, taxonomy terms) using a new rule structure instead of post metadata
  • Modified is_post_restricted() to use the refactored gate matching and track which gate restricts each post via $post_gate_id_map
  • Enhanced restrict_post() with additional checks to ensure only singular posts matching the queried object are restricted

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
includes/content-gate/class-content-restriction-control.php Implements content rule evaluation logic, adds gate ID tracking via static property, and introduces get_gate_post_id() filter callback to retrieve the restricting gate for each post
includes/content-gate/class-content-gate.php Adds singular/queried object checks to restrict_post(), simplifies is_post_restricted() return logic, adds post ID parameter to gate filter, ensures minimum visible paragraphs, and removes unused description field from gate structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miguelpeixe I ran into a handful of issues testing this PR. Because I wasn't sure if they were because of the changes here or just due to all of the merges and PRs we've done around these features lately, I opened two new PRs to fix them on my local site:

  • #4338
    • Fixes several issues with the sanitize_gate method (UI has no expected description field, sanitize_access_rule converts an array of product IDs to strings via sanitize_text_field, etc)
    • Changes the UI element for selecting subscription products to a FormTokenField: the UI only let you choose a single value, but the back-end expects an array of values.
    • Corrects the content rule slug when evaluating the post_types rule (note plural)
    • Fixes a fatal error due to mismatched parameters from the newspack_content_gate_restrict_post filter hook in class-content-gifting.php
  • Automattic/newspack-blocks#2264
    • I'm not sure why this is happening only with this branch, but I was seeing a fatal after a successful modal checkout while on this branch. This PR should fix the fatal and ensure that the custom thankyou.php template is shown after a modal checkout transaction.

If the changes in these PRs look good, feel free to merge them and I can re-test!

@github-actions github-actions bot added the [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator label Dec 2, 2025
@miguelpeixe
Copy link
Member Author

Thank you for addressing them! I've also faced issues while retesting, and it looks good in your branch.

@miguelpeixe miguelpeixe requested a review from dkoo December 3, 2025 14:58
* fix(content-gates): resolve fatals and mismatched data types

* fix: remove description field from update expected payload
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working with the fixes applied!

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator labels Dec 3, 2025
@miguelpeixe miguelpeixe merged commit 4034103 into trunk Dec 3, 2025
8 checks passed
@miguelpeixe miguelpeixe deleted the feat/content-gate-restriction-rules branch December 3, 2025 18:29
@github-actions
Copy link

github-actions bot commented Dec 3, 2025

Hey @miguelpeixe, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

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! ❤️

matticbot pushed a commit that referenced this pull request Dec 11, 2025
# [6.28.0-alpha.1](v6.27.1...v6.28.0-alpha.1) (2025-12-11)

### Bug Fixes

* **content-gating:** never gate special pages ([#4340](#4340)) ([a4dcfdd](a4dcfdd))
* **countdown-banner:** don't show on unrestricted posts ([#4349](#4349)) ([66d2c94](66d2c94))
* **indesign-export:** only register the attribute for allowed blocks ([#4330](#4330)) ([e1801cb](e1801cb))
* **my-account:** safe content argument to skip sanitization ([#4326](#4326)) ([b066de5](b066de5))
* **my-account:** set new payment method as default ([#4343](#4343)) ([6ebcaf9](6ebcaf9))
* **my-account:** support dynamic content around shortcode ([#4328](#4328)) ([36b9524](36b9524))
* **subscription-tiers-modal:** skip private products ([#4337](#4337)) ([564d803](564d803))

### Features

* **content-gate:** content rules ([#4265](#4265)) ([b5b8cd9](b5b8cd9))
* **content-gate:** implement restriction rules ([#4251](#4251)) ([4034103](4034103))
* metered content countdown banner ([#4315](#4315)) ([c9a68cc](c9a68cc))
* **payment-notice:** detect equivalent subscription ([#4333](#4333)) ([9a98889](9a98889))
* **ras:** OAuth OTP flow improvements ([#4341](#4341)) ([8b345fa](8b345fa))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 6.28.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jan 5, 2026
# [6.28.0](v6.27.4...v6.28.0) (2026-01-05)

### Bug Fixes

* **content-gating:** never gate special pages ([#4340](#4340)) ([a4dcfdd](a4dcfdd))
* **countdown-banner:** don't show on unrestricted posts ([#4349](#4349)) ([66d2c94](66d2c94))
* **countdown-banner:** never show more views than total ([#4369](#4369)) ([0ef3a24](0ef3a24))
* **indesign-export:** only register the attribute for allowed blocks ([#4330](#4330)) ([e1801cb](e1801cb))
* **my-account:** safe content argument to skip sanitization ([#4326](#4326)) ([b066de5](b066de5))
* **my-account:** set new payment method as default ([#4343](#4343)) ([6ebcaf9](6ebcaf9))
* **my-account:** support dynamic content around shortcode ([#4328](#4328)) ([36b9524](36b9524))
* **subscription-tiers-modal:** skip private products ([#4337](#4337)) ([564d803](564d803))

### Features

* **content-gate:** content rules ([#4265](#4265)) ([b5b8cd9](b5b8cd9))
* **content-gate:** implement restriction rules ([#4251](#4251)) ([4034103](4034103))
* metered content countdown banner ([#4315](#4315)) ([c9a68cc](c9a68cc))
* **payment-notice:** detect equivalent subscription ([#4333](#4333)) ([9a98889](9a98889))
* **ras:** OAuth OTP flow improvements ([#4341](#4341)) ([8b345fa](8b345fa))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 6.28.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants