Make WordPress Core

Changeset 39629

Timestamp:
12/21/2016 05:18:24 AM (8 years ago)
Author:
pento
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.

Merge of [39598] to the 4.7 branch.

Props jblz, tyxla.
Fixes #39092.

Location:
branches/4.7
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-admin/includes/post.php

    r39391 r39629  
    11531153
    11541154    return $q;
    1155 }
    1156 
    1157 /**
    1158  * Filter the SQL clauses of an attachment query to include filenames.
    1159  *
    1160  * @since 4.7.0
    1161  * @access private
    1162  *
    1163  * @global wpdb $wpdb WordPress database abstraction object.
    1164  *
    1165  * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
    1166  *                       DISTINCT, fields (SELECT), and LIMITS clauses.
    1167  * @return array The modified clauses.
    1168  */
    1169 function _filter_query_attachment_filenames( $clauses ) {
    1170     global $wpdb;
    1171     remove_filter( 'posts_clauses', __FUNCTION__ );
    1172 
    1173     // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
    1174     $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
    1175 
    1176     $clauses['groupby'] = "{$wpdb->posts}.ID";
    1177 
    1178     $clauses['where'] = preg_replace(
    1179         "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
    1180         "$0 OR ( sq1.meta_value $1 $2 )",
    1181         $clauses['where'] );
    1182 
    1183     return $clauses;
    11841155}
    11851156
  • branches/4.7/src/wp-includes/post.php

    r39507 r39629  
    61896189    return $post_name;
    61906190}
     6191
     6192
     6193
     6194
     6195
     6196
     6197
     6198
     6199
     6200
     6201
     6202
     6203
     6204
     6205
     6206
     6207
     6208
     6209
     6210
     6211
     6212
     6213
     6214
     6215
     6216
     6217
     6218
     6219
  • branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r39348 r39629  
    4646                $query_args['post_mime_type'] = $request['mime_type'];
    4747            }
     48
     49
     50
     51
     52
    4853        }
    4954
  • branches/4.7/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r39610 r39629  
    11571157    }
    11581158
     1159
     1160
     1161
     1162
     1163
     1164
     1165
     1166
     1167
     1168
     1169
     1170
     1171
     1172
     1173
     1174
     1175
     1176
     1177
     1178
    11591179    public function additional_field_get_callback( $object, $request ) {
    11601180        return 123;
Note: See TracChangeset for help on using the changeset viewer.