WordPress.org

Make WordPress Core

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

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

Revised filters, after discussion with @scribu for best-practice methods

  • wp-includes/comment.php

     
    216216                );
    217217
    218218                $args = wp_parse_args( $args, $defaults );
     219                $args = apply_filters_ref_array( 'pre_get_comments', array( $args, &$this ) );
    219220                extract( $args, EXTR_SKIP );
    220221
    221222                // $args can be whatever, only use the args defined in defaults to compute the key
     
    304305                if ( '' !== $search )
    305306                        $post_where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) );
    306307
     308                $pieces = array( 'post_where', 'orderby', 'order', 'limit' );
     309                $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
     310                foreach ( $pieces as $piece )
     311                        $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
     312
    307313                if ( $count )
    308314                        return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments $post_where ORDER BY $orderby $order $limit" );
    309315
    310316                $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments $post_where ORDER BY $orderby $order $limit" );
     317                $comments = apply_filters_ref_array('the_comments', array( $comments, &$this ) );
    311318
    312319                wp_cache_add( $cache_key, $comments, 'comment' );
    313320