fix(posts-inserter): show featured images for all post types#337
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes missing featured images in the Newspack Newsletters “Posts Inserter” block when inserting non-post content (e.g., pages, newsletters, events) by registering the REST “extra info” fields across all post types the inserter can select in the editor.
Changes:
- Expand
Newspack_Newsletters_Editor::add_newspack_extra_info()REST field registration from onlypostto all eligible post types (viewable +show_ui). - Add regression tests asserting
featured_media_info(and sibling fields) are registered for inserter-eligible post types and excluded for ineligible ones.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| plugins/newspack-newsletters/includes/class-newspack-newsletters-editor.php | Registers inserter-required REST fields (featured_media_info, author/byline, sponsors) for all inserter-eligible post types instead of only post. |
| plugins/newspack-newsletters/tests/test-posts-inserter-rest-fields.php | Adds regression coverage to ensure field registration matches the inserter’s eligible post-type scope. |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dkoo
left a comment
There was a problem hiding this comment.
Passes manual testing. Clean, well-scoped fix for NPPM-2756. The computed post-type list (show_ui + show_in_rest + is_post_type_viewable) correctly mirrors the Posts Inserter's own /wp/v2/types selector, so the registered fields match the set the block can actually offer. Keeping all four fields at context => [ 'edit' ] contains any exposure concern from the wider registration, and the regression test isolates each inclusion/exclusion gate well. Two non-blocking notes below — both pre-existing in the callbacks this PR re-scopes, so reasonable to address here or consciously defer.
Notes on code outside this PR’s changed lines (can’t be posted inline, so collected here):
plugins/newspack-newsletters/includes/class-newspack-newsletters-editor.php:892— Suggestion:newspack_get_author_info()callsget_coauthors()with no argument, so when Co-Authors Plus is active it resolves authors from the global$postrather than the$post['id']being serialized. REST collection callbacks run per item withoutsetup_postdata(), so the global is generally unset during serialization and this branch can return empty/wrong author data. This was effectively dormant before: onpostthe field is overridden by newspack-plugin's own priority-11 registration, and it wasn't registered anywhere else — so it was never reached. This PR makes it live for Pages/Newsletters/Events. It only affects author display in the inserter (not the featured image), but since it's in the function set being re-scoped, considerget_coauthors( $post['id'] )here, or note it as a conscious defer.
| * The sibling fields that are always registered (author info, custom | ||
| * byline) must follow the same post-type scope. | ||
| */ | ||
| public function test_sibling_fields_share_the_same_scope() { |
There was a problem hiding this comment.
Nit: The tests pin registration scope well but don't assert the context => [ 'edit' ] schema — which is the property the safety argument for the wider registration rests on. A regression dropping edit context (exposing author/sponsor data in view context) would pass silently. A one-line assertion that the registered field args carry context => [ 'edit' ] would cheaply lock that down. (The function_exists( '\Newspack_Sponsors\…' ) branch for newspack_sponsors_info is also unexercised, but that's lower-value.)
There was a problem hiding this comment.
Thanks @dkoo!
Done.
test_extra_fields_are_edit_context_only() (d469426) verifies all three always-on fields (newspack_author_info, newspack_custom_byline, featured_media_info) carry context => [ 'edit' ] and test_featured_media_info_schema_is_object() (f9903e0) pins the schema type.
The \Newspack_Sponsors\… branch stays uncovered — exercising it would add Sponsors to the newsletters test dependencies for behavior outside this change.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
plugins/newspack-newsletters/includes/class-newspack-newsletters-editor.php:784
newspack_sponsors_infois declared with schematype => 'array', but\Newspack_Sponsors\get_all_sponsors()can returnfalsewhen there are no sponsors. With this field now registered for more post types, returning a boolean here can violate the schema and complicate client handling. Consider normalizing the REST field output to always be an array (e.g., return[]when the helper returnsfalse).
register_rest_field(
$post_types,
'newspack_sponsors_info',
[
'get_callback' => [ __CLASS__, 'newspack_get_sponsors_info' ],
'schema' => [
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx
|
Thanks @dkoo — both notes addressed.
Same issue in the non-CAP fallback branch, which read |
|
Hey @wil-gerken, good job getting this PR merged! 🎉 Now, the 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! ❤️ |
## newspack-newsletters [3.34.2](https://github.com/Automattic/newspack-workspace/compare/newspack-newsletters@3.34.1...newspack-newsletters@3.34.2) (2026-06-22) ### Bug Fixes * **posts-inserter:** show featured images for all post types ([#337](#337)) ([c4e9b51](c4e9b51))
## [2.23.4](https://github.com/Automattic/newspack-workspace/compare/newspack-theme@2.23.3...newspack-theme@2.23.4) (2026-06-23) ### Bug Fixes * **posts-inserter:** show featured images for all post types ([#337](#337)) ([c4e9b51](c4e9b51)) * **theme:** stop Custom Fields box overwriting editor post meta ([#375](#375)) ([3738a64](3738a64)) * **woocommerce:** scope payment notice to recoverable statuses ([#301](#301)) ([1f55c11](1f55c11))
Changes proposed in this Pull Request:
The Posts Inserter block in a newsletter can pull in different content types — posts, pages, newsletters, events, and other types the block offers — and show each item's featured image. Featured images were only appearing for regular Posts: pages, newsletters, and events came through as text only, even when they had a featured image set. This restores the image for all of those.
The block builds each image from a piece of REST data the editor attaches to every item. That data was only attached to posts, so the block had nothing to draw from for other content types. This change attaches it to every content type the Posts Inserter lets you choose, including Events Calendar events.
Reference: NPPM-2756
How to test the changes in this Pull Request:
Release risk: Medium
Risk is medium because this touches editor REST data in a broadly adopted plugin. The change is additive, limited to edit-context fields, and covered by new regression tests.
Notes for reviewers
Newspack_Newsletters_Editor::add_newspack_extra_info()registeringfeatured_media_info(andnewspack_author_info,newspack_custom_byline,newspack_sponsors_info) viaregister_rest_field( 'post', … )only. The inserter fetches each type through its own REST route viagetEntityRecords( 'postType', postType ), so non-postroutes lacked the field, and with no client-side media fallback the editor showed no image.getMedia()fetch, which worked across post types, to the server-providedfeatured_media_infofield scoped topost. This keeps the server-provided field and registers it for the same post types the inserter offers./wp/v2/typesselector (viewable === true && show_ui === true):array_values( array_filter( get_post_types( [ 'show_ui' => true ], 'names' ), 'is_post_type_viewable' ) ). That keeps coverage aligned with the inserter, includingtribe_events.context => ['edit'], so the wider registration is not exposed to anonymous or view-context requests.newspack_author_infois also registered by newspack-plugin (Co-Authors Plus) at priority 11 forpostonly; that enriched version still wins onpost, and the newsletters field only adds coverage for other post types.show_ui-but-not-viewable CPT is out of scope. The exclusion test fails if theis_post_type_viewablefilter is removed.All Submissions:
Other information:
🤖 Generated with Claude Code