Make WordPress Core


Ignore:
Timestamp:
10/17/2022 11:17:38 AM (2 years ago)
Author:
audrasjb
Message:

Media: Refactor search by filename within the admin.

Props vortfu, xknown, peterwilsoncc, paulkevan.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r54377 r54524  
    79347934
    79357935/**
    7936  * Filters the SQL clauses of an attachment query to include filenames.
    7937  *
    7938  * @since 4.7.0
    7939  * @access private
    7940  *
    7941  * @global wpdb $wpdb WordPress database abstraction object.
    7942  *
    7943  * @param string[] $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
    7944  *                          DISTINCT, fields (SELECT), and LIMITS clauses.
    7945  * @return string[] The modified array of clauses.
    7946  */
    7947 function _filter_query_attachment_filenames( $clauses ) {
    7948     global $wpdb;
    7949     remove_filter( 'posts_clauses', __FUNCTION__ );
    7950 
    7951     // Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
    7952     $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
    7953 
    7954     $clauses['groupby'] = "{$wpdb->posts}.ID";
    7955 
    7956     $clauses['where'] = preg_replace(
    7957         "/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
    7958         '$0 OR ( sq1.meta_value $1 $2 )',
    7959         $clauses['where']
    7960     );
    7961 
    7962     return $clauses;
    7963 }
    7964 
    7965 /**
    79667936 * Sets the last changed time for the 'posts' cache group.
    79677937 *
Note: See TracChangeset for help on using the changeset viewer.