Skip to content

fix: Preserve featured image metadata in WP REST API upload responses#22607

Merged
dcalhoun merged 3 commits intotrunkfrom
fix/featured-image-not-set-for-app-password-sites
Feb 18, 2026
Merged

fix: Preserve featured image metadata in WP REST API upload responses#22607
dcalhoun merged 3 commits intotrunkfrom
fix/featured-image-not-set-for-app-password-sites

Conversation

@dcalhoun
Copy link
Copy Markdown
Member

@dcalhoun dcalhoun commented Feb 18, 2026

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 MediaRSApiRestClient and BaseWPV2MediaRestClient create a new MediaModel from the API response but don't carry over app-level metadata from the original model—specifically localPostId and markedLocallyAsFeatured.

Without markedLocallyAsFeatured = true, the upload completion handler in EditPostActivity.onUploadSuccess() takes the wrong branch—it treats the media as a regular editor upload instead of a featured image, so setFeaturedImageId() 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:

Fix: Preserve localPostId and markedLocallyAsFeatured (and id for BaseWPV2MediaRestClient) 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:

  1. Connect a self-hosted WordPress site using an application password
  2. Create a new post
  3. Open the post settings pane
  4. Tap "Set Featured Image"
  5. Select an image from the device (not from the WP media library)
  • Verify the image uploads and the featured image is set successfully
  • Verify the featured image thumbnail appears in the post settings pane

Verify setting featured image from an Image block still works:

  1. On a self-hosted site with an application password, create a new post
  2. Add an Image block and select an image
  3. Use the block's menu to "Set as Featured Image"
  • Verify the featured image is set successfully

Verify no regression on WP.com sites:

  1. Open an existing post on a WP.com site
  2. Open the post settings pane
  3. Set a featured image from the device
  • Verify the featured image is set successfully

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.
@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Feb 18, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
FlavorJalapeno
Build TypeDebug
Versionpr22607-9b822a3
Build Number1484
Application IDcom.jetpack.android.prealpha
Commit9b822a3
Installation URL011pnmvp6e508
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Feb 18, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
FlavorJalapeno
Build TypeDebug
Versionpr22607-9b822a3
Build Number1484
Application IDorg.wordpress.android.prealpha
Commit9b822a3
Installation URL32imug3b02pjg
Note: Google Login is not supported on these builds.

@dcalhoun dcalhoun marked this pull request as ready for review February 18, 2026 19:53
@sonarqubecloud
Copy link
Copy Markdown

@dcalhoun dcalhoun enabled auto-merge (squash) February 18, 2026 19:53
@dcalhoun dcalhoun requested a review from nbradbury February 18, 2026 20:24
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.15%. Comparing base (5fb2396) to head (9b822a3).
⚠️ Report is 2 commits behind head on trunk.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

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

Nice fix! :shipit:

@dcalhoun dcalhoun merged commit ec80fe6 into trunk Feb 18, 2026
27 of 28 checks passed
@dcalhoun dcalhoun deleted the fix/featured-image-not-set-for-app-password-sites branch February 18, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants