WordPress.org

Make WordPress Core

Opened 4 months ago

Last modified 4 weeks ago

#41692 new defect (bug)

REST API does not return featured_media for Audio/Video

Reported by: wonderboymusic Owned by:
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-patch
Focuses: Cc:

Description

Audio and Video attachments can have a featured image. This data is not currently returned by the REST API wp/v2/media endpoint. Part of the problem is that the schema for attachments is generated by the Post controller, even though the Post controller does not return data for attachments. Because the schema is used by the OPTIONS endpoint, before knowing what mime-type the attachment is, thumbnail should be set for attachment's attributes so that featured_media is added to the responses from wp/v2/media.

Attachments (2)

rest-thumbnail.diff (1.4 KB) - added by wonderboymusic 4 months ago.
41692.2.diff (6.9 KB) - added by TimothyBlynJacobs 3 months ago.

Download all attachments as: .zip

Change History (8)

#1 @rmccue
4 months ago

Makes sense to me.

On the patch, is there a reason to explicitly set featured_media? It looks to me like setting in the schema should be enough to add it to the response.

This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.


3 months ago

#3 @TimothyBlynJacobs
3 months ago

Taking a look at this after discussion in the REST API bug scrub Friday.

Core doesn't register the attachment post type with support for thumbnail. So just including thumbnail in the fixed schema is causes issues with the ::check_post_data() unit test method.

The first patch lists featured_media in the schema as read-write, but it only supports read. This is because the attachments controller doesn't call parent::create_item() which has the support for setting the featured media.

So that leaves us with three options I think.

  1. Add thumbnail support for the attachments post type and manually update the thumbnail in the attachments controller. I've attached the patch that does this. I have no idea what the ramifications are for listing thumbnail as supported in the post type, though.
  2. Same as #1, except don't include thumbnail support in the attachment post type and update ::check_post_data to either use the schema instead of post_type_supports() or just make an exception for the attachment post type.
  3. Continue with the first patch, but mark the featured media schema as readonly.

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


2 months ago

#5 @kadamwhite
2 months ago

  • Milestone changed from 4.9 to Future Release

Punting to future release, per discussion with @TimothyBlynJacobs in this week's REST API team chat

#6 @wonderboymusic
4 weeks ago

  • Milestone changed from Future Release to 5.0
Note: See TracTickets for help on using tickets.