-
Notifications
You must be signed in to change notification settings - Fork 3.2k
REST API: Support multiple media types and MIME types when listing media #9211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
b3e0dbc to
5e06d31
Compare
5e06d31 to
5fe24dd
Compare
ramonjd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this PR!
Sorry I didn't see it sooner.
Are you able to rebase and get it ready for a final review?
| } | ||
|
|
||
| $media_types = $this->get_media_types(); | ||
| $all_mime_types = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a @since 6.9.0 annotation in the doc block. 🤞🏻 this makes it to 6.9!
E.g., @since 6.9.0 Extends the media_type and mime_type request arguments to support array values.
| $mime_type_input = is_array( $request['mime_type'] ) | ||
| ? $request['mime_type'] | ||
| : explode( ',', $request['mime_type'] ); | ||
|
|
||
| $all_mime_types = array_merge( $all_mime_types, array_map( 'trim', $mime_type_input ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need the former check to see if the mime type prefix part is available in $media_types?
| 'description' => __( 'Limit result set to attachments of a particular media type.' ), | ||
| 'type' => 'string', | ||
| 'enum' => array_keys( $media_types ), | ||
| 'description' => __( 'Limit result set to attachments of particular media types.' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above, this method's docblock needs an annotation:
|
Also needs to update the API fixtures in tests/qunit/fixtures/wp-api-generated.js by running the
That should get the tests passing. |
|
@himanshupathak95 If you don't mind, I'd like to push this forward. I'll move your changes over to #10054 and give you props. |
…ents Controller to support array values for filtering. Updated tests to validate functionality and ensure compatibility with existing features. Pulling over work from WordPress#9211 Props to @himanshupathak95
|
Pulling across your work to #10054 so we can get it moving. Thank you! |
…ents Controller to support array values for filtering. Updated tests to validate functionality and ensure compatibility with existing features. Pulling over work from WordPress#9211 Props to @himanshupathak95
Trac ticket: https://core.trac.wordpress.org/ticket/63668
This patch enhances the REST API media endpoint to allow filtering by multiple values for the
media_typeandmime_typeparameters. This enables more flexible queries, such as requesting images and videos in a single API call.The implementation supports both comma-separated strings and arrays for input, while maintaining full backward compatibility. Unit tests are included to cover the new functionality and edge cases.