]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/post.php
WordPress 4.7.1
[autoinstalls/wordpress.git] / wp-includes / post.php
index c81f5c589e769596ef8ea9cc5335ad445badbae8..d9c64f5bfe9febb09517ee2b508f457e8c4e2574 100644 (file)
@@ -6188,3 +6188,32 @@ function wp_add_trashed_suffix_to_post_name_for_post( $post ) {
        clean_post_cache( $post->ID );
        return $post_name;
 }
        clean_post_cache( $post->ID );
        return $post_name;
 }
+
+/**
+ * Filter the SQL clauses of an attachment query to include filenames.
+ *
+ * @since 4.7.0
+ * @access private
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
+ * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
+ *                       DISTINCT, fields (SELECT), and LIMITS clauses.
+ * @return array The modified clauses.
+ */
+function _filter_query_attachment_filenames( $clauses ) {
+       global $wpdb;
+       remove_filter( 'posts_clauses', __FUNCTION__ );
+
+       // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
+       $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
+
+       $clauses['groupby'] = "{$wpdb->posts}.ID";
+
+       $clauses['where'] = preg_replace(
+               "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
+               "$0 OR ( sq1.meta_value $1 $2 )",
+               $clauses['where'] );
+
+       return $clauses;
+}