fix: Preserve featured image metadata in WP REST API upload responses#22607
Merged
fix: Preserve featured image metadata in WP REST API upload responses#22607
Conversation
The WP REST API V2 and Rust media clients were creating new MediaModel instances from upload responses without carrying over app-level metadata (localPostId and markedLocallyAsFeatured) from the original model. Without markedLocallyAsFeatured, the upload completion handler treats the media as a regular editor upload instead of a featured image, so setFeaturedImageId() is never called. This only affected self-hosted sites using application passwords, since WP.com and XMLRPC clients already preserved these fields. Fixes CMM-1254
Extend MediaRsApiRestClientTest and WPComV2MediaRestClientTest to verify that localPostId and markedLocallyAsFeatured are preserved from the original media model in the upload response payload.
Contributor
|
|
Contributor
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #22607 +/- ##
=======================================
Coverage 38.14% 38.15%
=======================================
Files 2247 2247
Lines 112972 112978 +6
Branches 15720 15720
=======================================
+ Hits 43096 43102 +6
Misses 66296 66296
Partials 3580 3580 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.





Description
Fix CMM-1254.
Fix a bug where featured images could not be set via the post settings pane on self-hosted sites using application passwords.
Root cause: When a media upload completes on the WP REST API path (used by self-hosted sites with application passwords), the
MediaRSApiRestClientandBaseWPV2MediaRestClientcreate a newMediaModelfrom the API response but don't carry over app-level metadata from the original model—specificallylocalPostIdandmarkedLocallyAsFeatured.Without
markedLocallyAsFeatured = true, the upload completion handler inEditPostActivity.onUploadSuccess()takes the wrong branch—it treats the media as a regular editor upload instead of a featured image, sosetFeaturedImageId()is never called.The WP.com REST client and XMLRPC client already preserve these fields, which is why the bug only affects self-hosted sites with application passwords:
MediaRestClient.java#L249-L252MediaXMLRPCClient.java#L231-L235MediaXMLRPCClient.java#L354-L357Fix: Preserve
localPostIdandmarkedLocallyAsFeatured(andidforBaseWPV2MediaRestClient) from the original media model when constructing the response model after a successful upload, matching the behavior of the WP.com and XMLRPC clients.Testing instructions
Set featured image from post settings on a self-hosted site:
Verify setting featured image from an Image block still works:
Verify no regression on WP.com sites: