fix(blocks): allow opted-in post types on the public /articles endpoint#522
Open
jason10lee wants to merge 2 commits into
Open
fix(blocks): allow opted-in post types on the public /articles endpoint#522jason10lee wants to merge 2 commits into
jason10lee wants to merge 2 commits into
Conversation
Restores Sponsors load-more in Homepage Posts / Carousel. #471 (NPPM-2964) narrowed the public /articles endpoint to is_post_type_viewable() types, which dropped the public=false Sponsors CPT, so a Sponsors-only block rendered page 1 via SSR but load-more returned empty. Adds a newspack_blocks_articles_allowed_post_types filter so a plugin can opt a specific non-viewable CPT into the endpoint (an explicit, per-CPT decision), without loosening the viewability gate for every type. newspack-sponsors opts in only its own CPT. Default is empty, so no behavior change for sites that don't. Resolves NPPM-2972. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Restores Sponsors “load more” behavior in Homepage Posts / Carousel by allowing explicit opt-in of non-viewable CPTs on the public newspack-blocks/v1/articles endpoint, without broadly loosening the endpoint’s visibility gate.
Changes:
- Added a
newspack_blocks_articles_allowed_post_typesallow-list filter to the public/articlesendpoint gating logic (viewable OR explicitly allow-listed). - Opted the Sponsors CPT into that allow-list from
newspack-sponsors, keeping the exposure decision co-located with the CPT definition. - Added a PHPUnit test to verify allow-listed non-viewable CPTs are served while other non-viewable CPTs remain excluded.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
plugins/newspack-sponsors/includes/class-core.php |
Hooks the new allow-list filter to permit the Sponsors CPT on the public /articles endpoint. |
plugins/newspack-blocks/src/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php |
Extends post-type filtering to include an explicit allow-list via newspack_blocks_articles_allowed_post_types. |
plugins/newspack-blocks/tests/test-homepage-posts-block.php |
Adds coverage for allow-listed non-viewable CPTs being served (and other non-viewable CPTs staying blocked). |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
Restores Sponsors load-more in Homepage Posts / Carousel (resolves NPPM-2972).
NPPM-2964 (#471) narrowed the public
/articlesendpoint tois_post_type_viewable()post types. The Sponsors CPT ispublic=false, so it's dropped there — a Sponsors-only block renders page 1 via SSR (which queries directly, not through/articles) but load-more / infinite-scroll returns empty.Design — explicit opt-in, not a broad marker:
newspack_blocks_articles_allowed_post_typesfilter:is_post_type_viewable( $type ) || in_array( $type, $allowed, true ). Default[]→ no behavior change for any site that doesn't opt in.I deliberately did not widen via
post_type_supports( 'newspack_blocks' )(the other option floated on the ticket). That marker is declared broadly (post,page, Events Calendar, Listings, Collections, Sponsors) and isn't a "safe to expose anonymously" signal — using it would auto-expose any futurepublic=falseCPT that opts into block support. The explicit filter keeps the anonymous-exposure decision auditable and owned by the plugin registering the CPT.Why this is a low-sensitivity opt-in: Sponsor data (name, logo, disclosure/byline) is already surfaced publicly as sponsor labels; the endpoint still returns only
publishstatus to anonymous callers; and #471'sspecificPostsprotection still holds for every type not on the allow-list (WP_Querypost_type∧post__inintersection).How to test the changes in this Pull Request:
n test-php --filter HomepagePostsBlockTest— the newtest_articles_endpoint_allows_filter_allowlisted_post_typepasses: an allow-listed non-viewable CPT is served and a non-allow-listed one is still dropped.build_articles_query, so this only realigns the REST path with it.Other information:
Note: the Sponsors-side opt-in isn't unit-tested (newspack-sponsors has no PHPUnit suite); the filter mechanism is covered in newspack-blocks, and the Sponsors query itself is exercised by the existing page-1 SSR path.