Skip to content

Conversation

@miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Oct 28, 2025

All Submissions:

Changes proposed in this Pull Request:

Implements the gate content rules and organizes content gate components.

How to test the changes in this Pull Request:

  1. Make sure you have the NEWSPACK_CONTENT_GATES constant set to true
  2. Navigate to Audience -> Content Gates
  3. Create a new gate
  4. Add multiple access rules and content rules (make sure to include taxonomy content rules)
  5. Set values for the rules and metering
  6. Click Save
  7. Refresh the page confirm the options persisted
  8. Reorder the gates using the arrows and drag (regression test)
  9. Refresh the page and confirm the order persisted

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
Copy link
Member

@rbcorrales rbcorrales left a comment

Choose a reason for hiding this comment

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

I'm now getting this error when trying to save, pointing to a recently updated line:

{
    "code": "qm_fatal",
    "message": "Uncaught Error: Cannot access offset of type string on string in /newspack-repos/newspack-plugin/includes/wizards/audience/class-audience-content-gates.php on line 285",
    "data": {
        "message": "Uncaught Error: Cannot access offset of type string on string",
        "file": "/newspack-repos/newspack-plugin/includes/wizards/audience/class-audience-content-gates.php",
        "line": 285,
        "trace": [
            {
                "file": "/newspack-repos/newspack-plugin/includes/wizards/audience/class-audience-content-gates.php",
                "line": 270,
                "function": "sanitize_access_rule",
                "class": "Newspack\\Audience_Content_Gates",
                "type": "->"
            },
            {
                "file": "/newspack-repos/newspack-plugin/includes/wizards/audience/class-audience-content-gates.php",
                "line": 237,
                "function": "sanitize_rules",
                "class": "Newspack\\Audience_Content_Gates",
                "type": "->"
            },
            {
                "file": "/var/www/html/wp-includes/rest-api/class-wp-rest-request.php",
                "line": 850,
                "function": "sanitize_gate",
                "class": "Newspack\\Audience_Content_Gates",
                "type": "->"
            },
...

The payload looks like this:

{
    "gate": {
        "id": 1376,
        "status": "publish",
        "title": "Another Gate",
        "description": "",
        "metering": {
            "enabled": true,
            "anonymous_count": "0",
            "registered_count": "0",
            "period": "week"
        },
        "priority": 0,
        "access_rules": [
            "automattic.com",
            {
                "slug": "email_domain",
                "value": "automattic.com"
            }
        ],
        "content_rules": [
            [
                "newspack_collection"
            ],
            {
                "slug": "post_types",
                "value": [
                    "newspack_collection"
                ]
            }
        ]
    }
}

@miguelpeixe
Copy link
Member Author

Thanks, @rbcorrales!

The sanitization hooks being incorrect (not executed at all) allowed for its logic to have a lot of inconsistencies 😅

Should be good after 3d8c23c. It's best to test with a fresh gate, as the sanitizer stored an incorrect data structure.

Copy link
Member

@rbcorrales rbcorrales left a comment

Choose a reason for hiding this comment

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

Thanks @miguelpeixe for addressing all the issues!

@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 2, 2025
@miguelpeixe
Copy link
Member Author

Thank you for the thorough review!

@miguelpeixe miguelpeixe merged commit b5b8cd9 into trunk Dec 2, 2025
12 checks passed
@miguelpeixe miguelpeixe deleted the feat/content-gate-restriction-control--content-rules branch December 2, 2025 16:21
@github-actions
Copy link

github-actions bot commented Dec 2, 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.

5 participants