Make WordPress Core

Changeset 16019


Ignore:
Timestamp:
10/27/2010 06:49:45 PM (14 years ago)
Author:
scribu
Message:

Add filters to WP_Comment_Query. Props sc0ttkclark. Fixes #15019

File:
1 edited

Legend:

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

    r16018 r16019  
    230230
    231231        $this->query_vars = wp_parse_args( $query_vars, $defaults );
    232 
     232        do_action_ref_array( 'pre_get_comments', array( &$this ) );
    233233        extract( $this->query_vars, EXTR_SKIP );
    234234
     
    300300        }
    301301
    302         $post_where = "WHERE $approved";
     302        $where = "WHERE $approved";
    303303
    304304        if ( ! empty($post_id) )
    305             $post_where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
     305            $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
    306306        if ( '' !== $author_email )
    307             $post_where .= $wpdb->prepare( 'AND comment_author_email = %s', $author_email );
     307            $where .= $wpdb->prepare( ' AND comment_author_email = %s', $author_email );
    308308        if ( '' !== $karma )
    309             $post_where .= $wpdb->prepare( 'AND comment_karma = %d', $karma );
     309            $where .= $wpdb->prepare( ' AND comment_karma = %d', $karma );
    310310        if ( 'comment' == $type )
    311             $post_where .= " AND comment_type = ''";
     311            $where .= " AND comment_type = ''";
    312312        elseif ( ! empty( $type ) )
    313             $post_where .= $wpdb->prepare( ' AND comment_type = %s', $type );
     313            $where .= $wpdb->prepare( ' AND comment_type = %s', $type );
    314314        if ( '' !== $parent )
    315             $post_where .= $wpdb->prepare( ' AND comment_parent = %d', $parent );
     315            $where .= $wpdb->prepare( ' AND comment_parent = %d', $parent );
    316316        if ( '' !== $user_id )
    317             $post_where .= $wpdb->prepare( ' AND user_id = %d', $user_id );
     317            $where .= $wpdb->prepare( ' AND user_id = %d', $user_id );
    318318        if ( '' !== $search )
    319             $post_where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) );
     319            $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) );
     320
     321        $pieces = array( 'where', 'orderby', 'order', 'limit' );
     322        $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
     323        foreach ( $pieces as $piece )
     324            $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
    320325
    321326        if ( $count )
    322             return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments $post_where ORDER BY $orderby $order $limit" );
    323 
    324         $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments $post_where ORDER BY $orderby $order $limit" );
     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" );
     330        $comments = apply_filters_ref_array( 'the_comments', array( $comments, &$this ) );
    325331
    326332        wp_cache_add( $cache_key, $comments, 'comment' );
Note: See TracChangeset for help on using the changeset viewer.