Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#57361 new enhancement

WP_REST_Attachments_Controller::get_media_types not returning existing mime types, but the ones allowed for upload

Reported by: david.binda Owned by:
Priority: normal Milestone: Awaiting Review
Component: REST API Version: 4.7
Severity: normal Keywords:
Cc: Focuses: rest-api

Description

While debugging an ​issue in Gutenberg's new media tab, it has been ​pointed out that the REST API does not actually allows to list items which are already in media library, but can no longer be uploaded (eg.: the list of allowed mime types changed over time).

That's different from what the wp-admin does, as it lists all items in the media library, no matter what their (mime)type is, and whether it can be uploaded or not.

The WP_REST_Attachments_Controller::get_media_types method uses the `get_allowed_mime_types()` function, which is upload oriented (returns a list of mime types which can be uploaded), while the listing in wp-admin uses a logic based on existing mime types in the library.

Thus I wonder, if the same logic as used in wp-admin should be used in the REST API, allowing users and developers to get a listing of all existing items in the media library, no matter whether new ones can be uploaded or not.

Change History (1)

#1 @TimothyBlynJacobs
4 years ago

I philosophically would support this change. The issue, however, is that get_available_post_mime_types is an uncached query. So we'd be adding an uncached query to every REST API load. So we can't simply move over to using the other function.

Note: See TracTickets for help on using tickets.