feat(content-gate): network product and access control#303
feat(content-gate): network product and access control#303miguelpeixe wants to merge 22 commits intotrunkfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds product-level “Network ID” support to Newspack Network to enable cross-site Content Gate access checks and to prevent duplicate subscription purchases across network sites.
Changes:
- Adds a WooCommerce Product “Network ID” metabox and stores it in product post meta.
- Syncs product Network IDs across the network via a new
newspack_network_product_updateddata event (incoming handler, event log item, and CLI backfiller). - Introduces Content Gate integrations for network-aware access decisions and subscription purchase limiting.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
includes/woocommerce/class-product-admin.php |
Adds admin UI + persistence for product Network ID metadata. |
includes/woocommerce/class-events.php |
Registers and emits the new product-updated data event. |
includes/incoming-events/class-product-updated.php |
Processes incoming product-updated events and stores synced product data. |
includes/hub/stores/event-log-items/class-product-updated.php |
Adds Hub event log summaries for product updates. |
includes/content-gate/class-access.php |
Grants Content Gate access based on matching Network IDs across sites. |
includes/content-gate/class-limit-purchase.php |
Blocks purchase/checkout when an equivalent network subscription already exists. |
includes/cli/backfillers/class-product-updated.php |
Backfills product-updated events for products with Network IDs. |
includes/class-initializer.php |
Boots the new Product admin and Content Gate integrations. |
includes/class-accepted-actions.php |
Allows newspack_network_product_updated events to be accepted/pulled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ic/newspack-network into feat/network-product-id
There was a problem hiding this comment.
I ran into issues matching up Network IDs when the products in question were variations of a variable subscription. Since the Network ID field attaches to the parent product instead of each individual variation (as I think it should), we should be crawling up the $product->get_parent_id() chain when comparing across sites. And/or, the network_id for a parent product needs to be populated for all of its variations/child products when syncing subscription data across sites.
Non-blocking feedback: I like the introduction of a Network ID string to allow publishers to manually map products across network sites. I wonder if we should also attempt to map by matching product slugs if the ID is empty, to reduce the overhead required for publishers? This probably won't be true of all networks, but many might have products with the same name across all network sites.
Good catch! Updated in a34d529. Testing it will require another product change event to populate the variant IDs.
This is the same strategy we have in place for membership plans:
I decided to keep it because:
|
dkoo
left a comment
There was a problem hiding this comment.
Thanks for the fix for variations, this is testing well now! Some more comments inline about the usage of get_post_meta vs $product->get_meta that I missed in the earlier review.
| if ( ! $product ) { | ||
| return; | ||
| } | ||
| $network_id = get_post_meta( $product->get_id(), Product_Admin::NETWORK_ID_META_KEY, true ); |
There was a problem hiding this comment.
Should this be $product->get_meta( Product_Admin::NETWORK_ID_META_KEY, true );?
There was a problem hiding this comment.
product is still a post type that supports update_post_meta() and get_post_meta(). I'd rather use the WP approach as it should be more stable and standardized. Is there a benefit in using the Woo layer here?
We're using update_post_meta() to set it:
| * @return string The Network ID, or empty string if not set. | ||
| */ | ||
| public static function get_network_id( $product_id ) { | ||
| $network_id = get_post_meta( $product_id, self::NETWORK_ID_META_KEY, true ); |
There was a problem hiding this comment.
Same as above, should we be using $product->get_meta( Product_Admin::NETWORK_ID_META_KEY, true );?
| if ( function_exists( 'wc_get_product' ) ) { | ||
| $product = wc_get_product( $product_id ); | ||
| if ( $product && $product->get_parent_id() ) { | ||
| return get_post_meta( $product->get_parent_id(), self::NETWORK_ID_META_KEY, true ); |
There was a problem hiding this comment.
Same as above, should we be using $product->get_meta( Product_Admin::NETWORK_ID_META_KEY, true );?
| * @param \WP_Post $post The post object. | ||
| */ | ||
| public static function render_meta_box( $post ) { | ||
| $network_id = get_post_meta( $post->ID, self::NETWORK_ID_META_KEY, true ); |
There was a problem hiding this comment.
Same as above, should we be using $product->get_meta( Product_Admin::NETWORK_ID_META_KEY, true );?

All Submissions:
Changes proposed in this Pull Request:
Add product-level Network IDs to integrate with content gating. This enables cross-site subscription access and purchase restrictions.
newspack_network_product_updateddata event, with incoming event handler, event log item, and CLI backfiller.newspack_access_rules_has_active_subscriptionfilter. When a user has an active subscription on another network site for a product with a matching Network ID, access is granted.Closes NPPD-1162.
How to test the changes in this Pull Request:
Other information: