Ticket #39092: 39092.diff
File 39092.diff, 3.2 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/post.php
1155 1155 } 1156 1156 1157 1157 /** 1158 * Filter the SQL clauses of an attachment query to include filenames.1159 *1160 * @since 4.7.01161 * @access private1162 *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;1184 }1185 1186 /**1187 1158 * Executes a query for attachments. An array of WP_Query arguments 1188 1159 * can be passed in, which will override the arguments set by this function. 1189 1160 * -
src/wp-includes/post.php
6183 6183 clean_post_cache( $post->ID ); 6184 6184 return $post_name; 6185 6185 } 6186 6187 /** 6188 * Filter the SQL clauses of an attachment query to include meta (filename/alt). 6189 * 6190 * @since 4.7.0 6191 * @access private 6192 * 6193 * @global wpdb $wpdb WordPress database abstraction object. 6194 * 6195 * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY, 6196 * DISTINCT, fields (SELECT), and LIMITS clauses. 6197 * @return array The modified clauses. 6198 */ 6199 function _filter_query_attachment_filenames( $clauses ) { 6200 global $wpdb; 6201 remove_filter( 'posts_clauses', __FUNCTION__ ); 6202 6203 // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs. 6204 $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND ( sq1.meta_key = '_wp_attached_file' OR sq1.meta_key = '_wp_attachment_image_alt' ) )"; 6205 6206 $clauses['groupby'] = "{$wpdb->posts}.ID"; 6207 6208 $clauses['where'] = preg_replace( 6209 "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/", 6210 "$0 OR ( sq1.meta_value $1 $2 )", 6211 $clauses['where'] ); 6212 6213 return $clauses; 6214 } -
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
275 275 } 276 276 } 277 277 278 // Filter query clauses to include filenames. 279 if ( isset( $query_args['s'] ) ) { 280 add_filter( 'posts_clauses', '_filter_query_attachment_filenames' ); 281 } 282 278 283 $posts_query = new WP_Query(); 279 284 $query_result = $posts_query->query( $query_args ); 280 285