Skip to content

Conversation

@himanshupathak95
Copy link

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_type and mime_type parameters. 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.

@github-actions
Copy link

github-actions bot commented Jul 8, 2025

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@himanshupathak95 himanshupathak95 marked this pull request as ready for review July 8, 2025 16:58
@github-actions
Copy link

github-actions bot commented Jul 8, 2025

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props abcd95, ramonopoly.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@ramonjd ramonjd left a 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();
Copy link
Member

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.

Comment on lines +101 to +105
$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 ) );
Copy link
Member

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.' ),
Copy link
Member

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:

@ramonjd
Copy link
Member

ramonjd commented Sep 30, 2025

Also needs to update the API fixtures in tests/qunit/fixtures/wp-api-generated.js by running the WP_Test_REST_Schema_Initialization test, e.g.,

npm run test:php -- --filter WP_Test_REST_Schema_Initialization

That should get the tests passing.

@ramonjd
Copy link
Member

ramonjd commented Oct 3, 2025

@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.

ramonjd added a commit to ramonjd/wordpress-develop that referenced this pull request Oct 3, 2025
…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
@ramonjd
Copy link
Member

ramonjd commented Oct 3, 2025

Pulling across your work to #10054 so we can get it moving.

Thank you!

@ramonjd ramonjd closed this Oct 3, 2025
ramonjd added a commit to ramonjd/wordpress-develop that referenced this pull request Oct 9, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants