Make WordPress Core

Ticket #63668: 63668.patch

File 63668.patch, 3.1 KB (added by abcd95, 9 months ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    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 { 
    8282                        $query_args['post_status'] = 'inherit';
    8383                }
    8484
    85                 $media_types = $this->get_media_types();
     85                $all_mime_types = array();
     86                $media_types    = $this->get_media_types();
    8687
    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                        }
    8998                }
    9099
    91100                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 ) );
    96110                }
    97111
    98112                // Filter query clauses to include filenames.
    class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 
    12851299                $params                            = parent::get_collection_params();
    12861300                $params['status']['default']       = 'inherit';
    12871301                $params['status']['items']['enum'] = array( 'inherit', 'private', 'trash' );
    1288                 $media_types                       = $this->get_media_types();
    12891302
    12901303                $params['media_type'] = array(
    12911304                        '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                        ),
    12951311                );
    12961312
    12971313                $params['mime_type'] = array(
    12981314                        '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                        ),
    13011320                );
    13021321
    13031322                return $params;