WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/13/2016 02:08:24 PM (4 years ago)
Author:
jnylen0
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r39595 r39598  
    11571157    }
    11581158
     1159    public function test_search_item_by_filename() {
     1160        $id = $this->factory->attachment->create_object( $this->test_file, 0, array(
     1161            'post_mime_type' => 'image/jpeg',
     1162        ) );
     1163        $id2 = $this->factory->attachment->create_object( $this->test_file2, 0, array(
     1164            'post_mime_type' => 'image/png',
     1165        ) );
     1166
     1167        $filename = basename( $this->test_file2 );
     1168
     1169        $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
     1170        $request->set_param( 'search', $filename );
     1171        $response = $this->server->dispatch( $request );
     1172        $data = $response->get_data();
     1173
     1174        $this->assertCount( 1, $data );
     1175        $this->assertEquals( $id2, $data[0]['id'] );
     1176        $this->assertEquals( 'image/png', $data[0]['mime_type'] );
     1177    }
     1178
    11591179    public function additional_field_get_callback( $object, $request ) {
    11601180        return 123;
Note: See TracChangeset for help on using the changeset viewer.