Make WordPress Core

Changeset 14478


Ignore:
Timestamp:
05/06/2010 06:03:05 PM (14 years ago)
Author:
nacin
Message:

Prevent ambiguous table aliases in wp_post_mime_type_where. props stephdau, jfarthing84, fixes #12750.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r14448 r14478  
    15741574 *
    15751575 * @param string|array $mime_types List of mime types or comma separated string of mime types.
     1576 * @param string $table_alias Optional. Specify a table alias, if needed. 
    15761577 * @return string The SQL AND clause for mime searching.
    15771578 */
    1578 function wp_post_mime_type_where($post_mime_types) {
     1579function wp_post_mime_type_where($post_mime_types, $table_alias = '') {
    15791580    $where = '';
    15801581    $wildcards = array('', '%', '%/%');
     
    16041605
    16051606        if ( false !== strpos($mime_pattern, '%') )
    1606             $wheres[] = "post_mime_type LIKE '$mime_pattern'";
     1607            $wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'";
    16071608        else
    1608             $wheres[] = "post_mime_type = '$mime_pattern'";
     1609            $wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'";
    16091610    }
    16101611    if ( !empty($wheres) )
  • trunk/wp-includes/query.php

    r14477 r14478  
    20272027                if ( !is_wp_error($post_ids) && !empty($post_ids) ) {
    20282028                    $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") ";
    2029                     if ( '' === $post_type ) {
     2029                    if ( empty($post_type) ) {
    20302030                        $post_type = 'any';
    20312031                        $post_status_join = true;
     
    20332033                        $post_status_join = true;
    20342034                    }
    2035                     $q['post_status'] = 'publish';
     2035                    if ( empty($q['post_status']) )
     2036                        $q['post_status'] = 'publish';
    20362037                } else {
    20372038                    $whichcat = " AND 0 ";
     
    20842085        // MIME-Type stuff for attachment browsing
    20852086
    2086         if ( isset($q['post_mime_type']) && '' != $q['post_mime_type'] )
    2087             $whichmimetype = wp_post_mime_type_where($q['post_mime_type']);
     2087        if ( isset($q['post_mime_type']) && '' != $q['post_mime_type'] ) {
     2088            $table_alias = $post_status_join ? $wpdb->posts : '';
     2089            $whichmimetype = wp_post_mime_type_where($q['post_mime_type'], $table_alias);
     2090        }
    20882091
    20892092        $where .= $search . $whichcat . $whichauthor . $whichmimetype;
Note: See TracChangeset for help on using the changeset viewer.