[wp-trac] [WordPress Trac] #41692: REST API does not return featured_media for Audio/Video
WordPress Trac
noreply at wordpress.org
Mon Jun 19 19:44:59 UTC 2023
#41692: REST API does not return featured_media for Audio/Video
--------------------------------------+-----------------------
Reporter: wonderboymusic | Owner: dlh
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 6.3
Component: REST API | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+-----------------------
Comment (by dlh):
I've opened a Pull Request for this ticket with an approach that tries to
handle the complications raised in the previous discussions.
First, with respect to post type support: Core registers thumbnail post
type support for the "pseudo post types" of `attachment:audio` and
`attachment:video`. See [27209]. These pseudo-types are checked in a few
places in core already. I decided to not try to change anything about that
and left out adding `thumbnail` support to the `attachment` type.
Second, as mentioned in the ticket description, the post type schema is
generated for `OPTIONS` requests without reference to a specific
attachment. So, `thumbnail` is added to the fixed schema attributes as was
also done in [attachment:"41692.2.diff"].
Third, what to do about a case where someone tries to add a featured image
to a MIME type that isn't audio or video?
I considered having the API reject the submission with an error, but that
punishment seemed disproportionate to the violation. It would also be
technically annoying, since the attachment would need to be created in
order to get the MIME type, then immediately deleted if it was rejected.
I also considered conditionally adding `thumbnail` to the attachment
schema based on whether post thumbnail support existed on the audio or
video media types. But I think that would imply that featured media could
be added to only those types, when in actuality the API wouldn't reject
featured media added to other types for the reason just given.
So, I landed on what you see in the PR: Featured media is always added to
the attachment schema and always handled, but a `_doing_it_wrong()` will
be issued if the attachment MIME type doesn't support thumbnails.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41692#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list