diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index 589e0e2cce..9e95a807f1 100644
|
a
|
b
|
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 82 | 82 | $query_args['post_status'] = 'inherit'; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | | $media_types = $this->get_media_types(); |
| | 85 | $all_mime_types = array(); |
| | 86 | $media_types = $this->get_media_types(); |
| 86 | 87 | |
| 87 | | if ( ! empty( $request['media_type'] ) && isset( $media_types[ $request['media_type'] ] ) ) { |
| 88 | | $query_args['post_mime_type'] = $media_types[ $request['media_type'] ]; |
| | 88 | if ( ! empty( $request['media_type'] ) ) { |
| | 89 | $media_type_input = is_array( $request['media_type'] ) |
| | 90 | ? $request['media_type'] |
| | 91 | : explode( ',', $request['media_type'] ); |
| | 92 | |
| | 93 | foreach ( array_map( 'trim', $media_type_input ) as $type ) { |
| | 94 | if ( isset( $media_types[ $type ] ) ) { |
| | 95 | $all_mime_types = array_merge( $all_mime_types, $media_types[ $type ] ); |
| | 96 | } |
| | 97 | } |
| 89 | 98 | } |
| 90 | 99 | |
| 91 | 100 | if ( ! empty( $request['mime_type'] ) ) { |
| 92 | | $parts = explode( '/', $request['mime_type'] ); |
| 93 | | if ( isset( $media_types[ $parts[0] ] ) && in_array( $request['mime_type'], $media_types[ $parts[0] ], true ) ) { |
| 94 | | $query_args['post_mime_type'] = $request['mime_type']; |
| 95 | | } |
| | 101 | $mime_type_input = is_array( $request['mime_type'] ) |
| | 102 | ? $request['mime_type'] |
| | 103 | : explode( ',', $request['mime_type'] ); |
| | 104 | |
| | 105 | $all_mime_types = array_merge( $all_mime_types, array_map( 'trim', $mime_type_input ) ); |
| | 106 | } |
| | 107 | |
| | 108 | if ( ! empty( $all_mime_types ) ) { |
| | 109 | $query_args['post_mime_type'] = array_values( array_unique( $all_mime_types ) ); |
| 96 | 110 | } |
| 97 | 111 | |
| 98 | 112 | // Filter query clauses to include filenames. |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { |
| 1285 | 1299 | $params = parent::get_collection_params(); |
| 1286 | 1300 | $params['status']['default'] = 'inherit'; |
| 1287 | 1301 | $params['status']['items']['enum'] = array( 'inherit', 'private', 'trash' ); |
| 1288 | | $media_types = $this->get_media_types(); |
| 1289 | 1302 | |
| 1290 | 1303 | $params['media_type'] = array( |
| 1291 | 1304 | 'default' => null, |
| 1292 | | 'description' => __( 'Limit result set to attachments of a particular media type.' ), |
| 1293 | | 'type' => 'string', |
| 1294 | | 'enum' => array_keys( $media_types ), |
| | 1305 | 'description' => __( 'Limit result set to attachments of particular media types.' ), |
| | 1306 | 'type' => array( 'string', 'array' ), |
| | 1307 | 'items' => array( |
| | 1308 | 'type' => 'string', |
| | 1309 | 'enum' => array_keys( $this->get_media_types() ), |
| | 1310 | ), |
| 1295 | 1311 | ); |
| 1296 | 1312 | |
| 1297 | 1313 | $params['mime_type'] = array( |
| 1298 | 1314 | 'default' => null, |
| 1299 | | 'description' => __( 'Limit result set to attachments of a particular MIME type.' ), |
| 1300 | | 'type' => 'string', |
| | 1315 | 'description' => __( 'Limit result set to attachments of particular MIME types.' ), |
| | 1316 | 'type' => array( 'string', 'array' ), |
| | 1317 | 'items' => array( |
| | 1318 | 'type' => 'string', |
| | 1319 | ), |
| 1301 | 1320 | ); |
| 1302 | 1321 | |
| 1303 | 1322 | return $params; |