WordPress.org

Make WordPress Core

Ticket #15019: wp-includes-comment-filters-fixed.patch

File wp-includes-comment-filters-fixed.patch, 2.9 KB (added by sc0ttkclark, 11 years ago)

Patch refreshed and revised with adjustments to the changes made by refresh - also fixed $post_where to be $where (for consistency) and resolved a bug with $author_email / $karma not adding a space before the AND in appending $where

  • wp-includes/comment.php

     
    229229                );
    230230
    231231                $this->query_vars = wp_parse_args( $query_vars, $defaults );
    232 
     232                apply_filters_ref_array( 'pre_get_comments', array( &$this ) );
    233233                extract( $this->query_vars, EXTR_SKIP );
    234234
    235235                // $args can be whatever, only use the args defined in defaults to compute the key
     
    299299                        $limit = '';
    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' ) );
    320320
     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 ] : '';
     325
    321326                if ( $count )
    322                         return $wpdb->get_var( "SELECT COUNT(*) 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" );
    323328
    324                 $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments $post_where ORDER BY $orderby $order $limit" );
     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' );
    327333