Repository navigation
REST API: Match attachment type filters against the stored type - #16371
jorgefilipecosta wants to merge 2 commits into
Conversation
The `media_type` and `mime_type` collection parameters of the attachments endpoint were resolved against the MIME types the current user can upload. A `mime_type` value outside that list was dropped, and when every value was dropped no filter was applied, so the request returned every attachment. A `media_type` group only matched the types the user can upload, so it missed stored attachments of other types in that group. Each `media_type` group is now passed to the query as the group itself, and each exact `mime_type` value as given, matching the stored type the way the Media Library does. A `mime_type` filter without valid values returns no attachments.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
This PR fixes the
media_typeandmime_typecollection params of/wp/v2/mediaso they match the stored attachment type instead of the current user's allowed upload types:media_typegroups are passed toWP_Queryas the group, which matches every storedgroup/*type.mime_typevalues are passed as given; values without a subtype or with wildcards match nothing.mime_typefilter without matching values returns no attachments instead of every attachment.media_typeenum is unchanged and still lists the groups the current user can upload.Drafted with AI assistance (Claude Code) and reviewed by me.
Trac ticket: https://core.trac.wordpress.org/ticket/66893
Testing
Verify unit tests are passing:
As an author,
wp.apiFetch( { path: '/wp/v2/media?mime_type=text/html' } )returns only HTML attachments (or[]) instead of the whole library.