Skip to content

fix(posts-inserter): show featured images for all post types#337

Merged
wil-gerken merged 12 commits into
releasefrom
hotfix/nppm-2756-posts-inserter-featured-image
Jun 22, 2026
Merged

fix(posts-inserter): show featured images for all post types#337
wil-gerken merged 12 commits into
releasefrom
hotfix/nppm-2756-posts-inserter-featured-image

Conversation

@wil-gerken

Copy link
Copy Markdown
Contributor

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:

  1. Make sure a Page has a featured image set. If The Events Calendar is active, give an Event one too.
  2. Create or open a newsletter and add a Posts Inserter block.
  3. Turn on Featured image and set Post type to Pages.
  4. Confirm the selected page shows its featured image. Before this change, only the title and text appeared.
  5. Repeat with Post type set to Newsletters and Events. Images should appear for each.
  6. Set Post type back to Posts and confirm those still work as before.

Release risk: Medium

Signal Score Evidence
Contract surface Low Not part of any tracked cross-repo contract; registers the existing edit-context REST fields for more post types, with no signature change.
Surface type Medium Changes REST response data for editor content types; not a new endpoint, not the newsletter send path.
Publisher exposure Medium Newspack Newsletters is broadly adopted, but the behavior change only affects Posts Inserter use with non-post content types.
Change shape Medium About 12 production lines in one file. Risk is a little higher because this registration was introduced by #1969. New tests added.

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

  • The missing image data traces to Newspack_Newsletters_Editor::add_newspack_extra_info() registering featured_media_info (and newspack_author_info, newspack_custom_byline, newspack_sponsors_info) via register_rest_field( 'post', … ) only. The inserter fetches each type through its own REST route via getEntityRecords( 'postType', postType ), so non-post routes lacked the field, and with no client-side media fallback the editor showed no image.
  • The #1969 change moved image data from a client-side getMedia() fetch, which worked across post types, to the server-provided featured_media_info field scoped to post. This keeps the server-provided field and registers it for the same post types the inserter offers.
  • The post-type list mirrors the inserter's own /wp/v2/types selector (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, including tribe_events.
  • All four fields are context => ['edit'], so the wider registration is not exposed to anonymous or view-context requests.
  • newspack_author_info is also registered by newspack-plugin (Co-Authors Plus) at priority 11 for post only; that enriched version still wins on post, and the newsletters field only adds coverage for other post types.
  • Tests cover both filter gates independently: a viewable CPT is in scope, and a show_ui-but-not-viewable CPT is out of scope. The exclusion test fails if the is_post_type_viewable filter is removed.

All Submissions:

  • Have you followed the Newspack Contributing guidelines?
  • Does your code follow the WordPress coding standards and VIP Go coding standards?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 17, 2026 16:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 only post to 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.

wil-gerken and others added 2 commits June 17, 2026 09:22
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread plugins/newspack-newsletters/includes/class-newspack-newsletters-editor.php Outdated
Comment thread plugins/newspack-newsletters/includes/class-newspack-newsletters-editor.php Outdated
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@wil-gerken wil-gerken marked this pull request as ready for review June 17, 2026 17:51
@wil-gerken wil-gerken requested a review from a team as a code owner June 17, 2026 17:51
@dkoo dkoo self-assigned this Jun 19, 2026

@dkoo dkoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:892Suggestion: newspack_get_author_info() calls get_coauthors() with no argument, so when Co-Authors Plus is active it resolves authors from the global $post rather than the $post['id'] being serialized. REST collection callbacks run per item without setup_postdata(), so the global is generally unset during serialization and this branch can return empty/wrong author data. This was effectively dormant before: on post the 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, consider get_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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

@wil-gerken wil-gerken Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added [Status] Approved Pull request has been approved and removed [Status] Needs Review labels Jun 19, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread plugins/newspack-newsletters/tests/test-posts-inserter-rest-fields.php Outdated
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx
@wil-gerken wil-gerken requested a review from Copilot June 22, 2026 18:58
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_info is declared with schema type => 'array', but \Newspack_Sponsors\get_all_sponsors() can return false when 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 returns false).
			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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LryLGecsPjop7ENpMEkgxx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@wil-gerken

wil-gerken commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @dkoo — both notes addressed.

get_coauthors(): now get_coauthors( $post['id'] ) (d469426) — resolves the right author once the field covers Pages/Newsletters/Events (#337).

Same issue in the non-CAP fallback branch, which read $post['author'] — a key WordPress omits for post types without author support, so the broadened registration would have produced an undefined-key warning and empty author data. Now get_post_field( 'post_author', $post['id'] ) (f9903e0), matching newspack-plugin's Author_Rest_Fields.

@wil-gerken wil-gerken merged commit c4e9b51 into release Jun 22, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown

Hey @wil-gerken, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

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! ❤️

matticbot pushed a commit that referenced this pull request Jun 22, 2026
## 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))
@wil-gerken wil-gerken deleted the hotfix/nppm-2756-posts-inserter-featured-image branch June 22, 2026 22:27
@wil-gerken wil-gerken assigned wil-gerken and unassigned dkoo Jun 22, 2026
matticbot pushed a commit that referenced this pull request Jun 23, 2026
## [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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Approved Pull request has been approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants