[wp-trac] [WordPress Trac] #35192: Comments_clauses filter

WordPress Trac noreply at wordpress.org
Mon Dec 21 22:37:43 UTC 2015


#35192: Comments_clauses filter
--------------------------+-----------------------------
 Reporter:  firebird75    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:  4.4
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hello,

 If I use this filter to modify the comment query :
 {{{
 $clauses = apply_filters_ref_array( 'comments_clauses', array( compact(
 $pieces ), &$this ) );
 }}}

 It works fine. The problem is that, due to change in WP 4.4, later on, you
 reach the fill_descendants function if you have some hierarchical
 comments. This one reuses the filtered fields from the comments_clauses
 filter, except the "where". So if you have modified the "from" and the
 "where", only the "from" is taken into consideration there :
 {{{
 $where = 'WHERE ' . implode( ' AND ', $where_clauses ) . ' AND
 comment_parent IN (' . implode( ',', array_map( 'intval', $parent_ids ) )
 . ')';
                         $comment_ids = $wpdb->get_col(
 "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where}
 {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID
 ASC" );
 }}}

 As you can see, the "where" is overriden. This will generate some SQL
 errors, especially if you have modified the "from" to include some table
 join that you then reference into the "where" to filter further.

 So either, we should have a way to filter as well as in the
 fill_descendants function, either the filtered from should be cleaned up
 to init it back to what it is by default. Otherwise, we have random
 behaviours here...

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35192>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list