Make WordPress Core

Changeset 16020


Ignore:
Timestamp:
10/27/2010 07:05:39 PM (14 years ago)
Author:
scribu
Message:

Make comment clauses more similar to post clauses. See #15019

File:
1 edited

Legend:

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

    r16019 r16020  
    293293        if ( !empty($number) ) {
    294294            if ( $offset )
    295                 $limit = 'LIMIT ' . $offset . ',' . $number;
     295                $limits = 'LIMIT ' . $offset . ',' . $number;
    296296            else
    297                 $limit = 'LIMIT ' . $number;
     297                $limits = 'LIMIT ' . $number;
    298298        } else {
    299             $limit = '';
     299            $limits = '';
    300300        }
    301301
    302         $where = "WHERE $approved";
     302        if ( $count )
     303            $fields = 'COUNT(*)';
     304        else
     305            $fields = '*';
     306
     307        $join = '';
     308        $where = $approved;
    303309
    304310        if ( ! empty($post_id) )
     
    319325            $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) );
    320326
    321         $pieces = array( 'where', 'orderby', 'order', 'limit' );
     327        $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' );
    322328        $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
    323329        foreach ( $pieces as $piece )
    324330            $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
    325331
     332        $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where ORDER BY $orderby $order $limits";
     333
    326334        if ( $count )
    327             return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments $where ORDER BY $orderby $order $limit" );
    328 
    329         $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments $where ORDER BY $orderby $order $limit" );
     335            return $wpdb->get_var( $query );
     336
     337        $comments = $wpdb->get_results( $query );
    330338        $comments = apply_filters_ref_array( 'the_comments', array( $comments, &$this ) );
    331339
Note: See TracChangeset for help on using the changeset viewer.