REST API: Add support for filename search in media endpoint.

In [38625], the functionality to search for attachments by filename was added
via the `posts_clauses` filter and the `_filter_query_attachment_filenames()`
function.  This moves `_filter_query_attachment_filenames()` from
`wp-admin/includes/post.php` to `wp-includes/post.php` so that it can be
applied in the same manner in the REST API media endpoint.

Props jblz, tyxla.
Fixes #39092.

Built from https://develop.svn.wordpress.org/trunk@39598


git-svn-id: http://core.svn.wordpress.org/trunk@39538 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
James Nylen
2016-12-13 14:09:42 +00:00
parent 7cc41e47ac
commit 505e135f4c
4 changed files with 35 additions and 30 deletions

View File

@@ -47,6 +47,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
}
}
// Filter query clauses to include filenames.
if ( isset( $query_args['s'] ) ) {
add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
}
return $query_args;
}