feat(content-gate): improve usability of the user Access Control report - #1031
feat(content-gate): improve usability of the user Access Control report#1031dkoo wants to merge 5 commits into
Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
A newly added test helper updates subscription meta without saving, which can make tests pass while diverging from real WooCommerce persistence behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR enhances the newspack-plugin Content Gate “Access Control” section shown on WordPress user profile screens by adding links to the relevant admin screens (gate editor, products, institutions) and by listing/linking the specific subscription(s) or order(s) that grant access for “Active subscription” and “One-time purchase” rules.
Changes:
- Update the user profile Access Control report UI to include linked gate/product/institution titles and (when applicable) linked
#<id>granting subscriptions/orders. - Add request-scoped, memoized helpers to enumerate granting subscription IDs and qualifying paid order IDs (newest-first, bounded/capped).
- Expand unit tests and WooCommerce mocks to cover granting-entity listing/link behavior and output escaping.
File summaries
| File | Description |
|---|---|
| plugins/newspack-plugin/includes/content-gate/class-user-gate-access.php | Renders the updated Access Control report and adds helper logic for formatting linked rule values and listing granting entities. |
| plugins/newspack-plugin/includes/content-gate/class-access-rules.php | Refactors subscription checks to share an ID-listing path and introduces paged paid-order listing for one-time purchase attribution. |
| plugins/newspack-plugin/tests/mocks/wc-mocks.php | Extends the WC order mock with get_edit_order_url() to support linking in tests. |
| plugins/newspack-plugin/tests/unit-tests/content-gate/class-user-gate-access.php | Adds/updates unit tests validating granting-record links, filtering, caps, and HTML escaping. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
@adekbadek requesting a human review mainly to ensure that the changes here don't have any side effects that could spiral beyond the user profile page context. |
thomasguillot
left a comment
There was a problem hiding this comment.
Design looks good to me. I ran it locally against a reader whose access comes from a group subscription, and having the granting #id right there in the report is exactly the shortcut that was missing.
All Submissions:
Changes proposed in this Pull Request:
The Access Control report on a user's profile told support whether a reader passes each gate, but not which record grants it. Finding the subscription or order meant a separate trip through WooCommerce. This is especially difficult when the user is granted access through a gifted or group subscription: searching the Subscriptions list page for a gift recipient or group member's name or email address fails to find their subscriptions, as the search only matches subscriptions by owner, not giftee or group member.
The report now links gate titles, product names, and institution names to their admin screens, and for passing "Active subscription" and "One-time purchase" rules lists the granting subscriptions or orders as
#idlinks to their edit screens.The rule evaluators are unchanged in behavior:
has_active_subscription()now delegates to a shared subscription-listing method, and the one-time-purchase order scan reads newest-first in pages and stops at the first match, so the front-end path does no more work than before.The report's profile hooks run at priority 9 so the section appears above other profile sections from this plugin and third parties. Anecdotal feedback from publishers suggests that they're looking at this info pretty frequently, so it should live relatively high-up in the user profile page.
Before
After
Closes NPPD-2243.
How to test the changes in this Pull Request:
NEWSPACK_CONTENT_GATESdefined, publish a content gate with custom access rules for a subscription product, a one-time product, and an institution.#id. Expect the subscription edit screen.#idlist.<b>. Expect the profile to show it as literal text.Other information: