Skip to content

feat(integrations): add content gate metadata#4605

Open
chickenn00dle wants to merge 3 commits intotrunkfrom
feat/add-content-gate-metadata
Open

feat(integrations): add content gate metadata#4605
chickenn00dle wants to merge 3 commits intotrunkfrom
feat/add-content-gate-metadata

Conversation

@chickenn00dle
Copy link
Copy Markdown
Contributor

@chickenn00dle chickenn00dle commented Mar 27, 2026

Summary

Implements the Content_Gate metadata class for reader activation sync, adding two fields that track whether a reader has access to gated content and what grants that access.

  • Content_Access: "Yes" or "No" — whether the reader can bypass any published content gate with custom access rules. Never empty.
  • Content_Access_Source: The entity granting access — subscription product name(s), "domain" (email domain rule), or "group" (institutional access). Empty when Content_Access is "No".

Makes User_Gate_Access::evaluate_gate_for_user() public so the metadata class can reuse its detailed per-rule evaluation results.

Fixes get_access_source_labels to only include product names the user has actually purchased, rather than all products configured on the gate rule. Uses Access_Rules::has_active_subscription() to check each product individually, covering both individual and group subscriptions.

Closes NPPD-1390

Test plan

  1. Enabled the following in wp-config.php:
define( 'NEWSPACK_LOG_LEVEL', 3 );
define( 'NEWSPACK_CONTENT_GATES', true );
define( 'NEWSPACK_SYNC_METADATA_VERSION', '1.0' );
define( 'NEWSPACK_INTEGRATIONS_SETTINGS_ENABLED', true );
  1. Navigate to Audience > Integrations > ESP and confirm the Content Access and Content Access Source fields are available in the outgoing metadata section
  2. Check them both and save, confirming they persist on reload
  3. Create two subscription products (e.g., "Premium Plan" and "Basic Plan")
  4. Create a content gate with a subscription access rule that includes both products
  5. As a new reader, register to the site
  6. Check the logs and verify the contact is synced with Content_Access = "No" and Content_Access_Source = empty (since the reader has no subscriptions)
  7. As the same reader, purchase only one of the two subscription products (e.g., "Basic Plan")
  8. Check the logs for another sync entry — verify Content_Access = "Yes" and Content_Access_Source = only the purchased product name (e.g., "Basic Plan"), NOT both products
    Screenshot 2026-03-30 at 13 53 38
  9. Now purchase the second subscription product as well
  10. Check the logs — verify Content_Access_Source now includes both product names
  11. Test with an email domain access rule — verify the source label is "domain" when the reader's email matches
  12. Test with an institution access rule — verify the source label is "group" when the reader matches
  13. Verify that when no custom access gates are configured, Content_Access = "Yes" with empty source

🤖 Generated with Claude Code

@chickenn00dle chickenn00dle marked this pull request as ready for review March 30, 2026 15:42
Copilot AI review requested due to automatic review settings March 30, 2026 15:42
@chickenn00dle chickenn00dle requested a review from a team as a code owner March 30, 2026 15:42
Copy link
Copy Markdown
Contributor

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

Adds Reader Activation Sync contact metadata for Content Gate access so ESP/CRM contacts can be annotated with whether they can bypass custom content gates and what grants that access.

Changes:

  • Implement Reader_Activation\Sync\Contact_Metadata\Content_Gate to compute Content_Access and Content_Access_Source from published content gates’ custom access rules.
  • Expose User_Gate_Access::evaluate_gate_for_user() publicly for reuse by the metadata class.
  • Add unit tests covering basic content-gate metadata behavior (primarily email domain rules).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
includes/reader-activation/sync/contact-metadata/class-content-gate.php Computes and returns Content Gate metadata fields for sync, including source derivation from per-rule evaluation.
includes/content-gate/class-user-gate-access.php Makes evaluate_gate_for_user() public so other components can reuse detailed evaluation results.
tests/unit-tests/content-gate/class-content-gate-metadata.php Adds unit tests validating metadata output for no gates, invalid user, and email-domain rule scenarios.

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

@chickenn00dle chickenn00dle force-pushed the feat/add-content-gate-metadata branch from 5f3c4c1 to be9c88e Compare March 30, 2026 17:47
@chickenn00dle chickenn00dle added the [Status] Needs Review The issue or pull request needs to be reviewed label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants