[wp-trac] [WordPress Trac] #41692: REST API does not return featured_media for Audio/Video
WordPress Trac
noreply at wordpress.org
Mon Nov 24 06:04:23 UTC 2025
#41692: REST API does not return featured_media for Audio/Video
-------------------------------------------------+-------------------------
Reporter: wonderboymusic | Owner: swissspidy
Type: enhancement | Status: closed
Priority: normal | Milestone: 6.5
Component: REST API | Version:
Severity: normal | Resolution: fixed
Keywords: has-patch has-unit-tests add-to- | Focuses:
field-guide |
-------------------------------------------------+-------------------------
Comment (by westonruter):
In working to fix PHPStan static analysis issues in #64238, @justlevine
and I have uncovered a couple issues with [57603]. First of all, the
`$schema` was never defined in the
`WP_REST_Attachments_Controller::update_item()` method, so the logic in
this `if` statement would never run:
{{{#!php
<?php
if ( ! empty( $schema['properties']['featured_media'] ) &&
isset( $request['featured_media'] ) ) {
$thumbnail_update = $this->handle_featured_media(
$request['featured_media'], $attachment->ID );
if ( is_wp_error( $thumbnail_update ) ) {
return $thumbnail_update;
}
}
}}}
There didn't appear to be test coverage for the error case, so this was
not noticed. Nevertheless, the featured media '''does''' get updated, and
this is because the parent method also calls this same
`handle_featured_media()` method. However, when this happens the result is
that `set_post_thumbnail()` is called twice. When passing the same values
into that function a second time, the function returns `false` causing it
to appear as if it failed, and then this causes the REST API endpoint to
newly return with an error.
@swissspidy @TimothyBlynJacobs @dlh @spacedmonkey Please review
[https://github.com/WordPress/wordpress-develop/pull/8865 this PR] to
validate the fix. Note how it includes an update to
`handle_featured_media()` to prevent calling `set_post_thumbnail()` when
the `_thumbnail_id` is already set. The PR also increases test coverage
for the error scenario.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41692#comment:44>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list