[wp-trac] [WordPress Trac] #19623: Use Comment API in comments_template, rather than hardcoded SQL

WordPress Trac noreply at wordpress.org
Mon Aug 11 19:11:34 UTC 2014


#19623: Use Comment API in comments_template, rather than hardcoded SQL
-------------------------------------+------------------------------
 Reporter:  simonwheatley            |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Comments                 |     Version:  3.3
 Severity:  major                    |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+------------------------------
Changes (by boonebgorges):

 * severity:  normal => major


Comment:

 I've run into this issue a number of times, when working on plugins that
 need to manipulate comments in one way or another. The direct queries in
 `comments_template()` effectively mean that all such plugins have to have
 two separate filters to do anything meaningful - one on `'comments_array'`
 and one somewhere in `WP_Comment_Query`. This is a bit embarassing, and
 kind of defeats the purpose of having an API. So I'd urge that the team
 consider this a high priority.

 19623.03.patch is an adaptation of 19623-2.diff that does the following:

 - Adds unit tests for the new WP_Comment_Query arguments
 - Improves adherence to WP coding standands
 - Reorganizes the logic of assembling the SQL query so that it's easier to
 understand

 I'm also attaching a patch 19623.backpat.patch. This contains a couple of
 PHPUnit integration tests that demonstrate that we're not breaking
 backward compatibility with these changes. `comments_template()` is (very)
 non-amenable to testing, so I had to do some crummy output buffering and
 filter tricks. The first three tests demonstrate that the comments pulled
 from the query are the same as the three if/else direct queries currently
 in `comments_template()`. The last test shows that plugins filter
 `'comments_array'` will continue to work. These are some pretty terrible
 looking tests, so I understand if they're not included in the core suite.
 But I did want to show programatically that the changes maintain full
 backward compatibility, by writing tests that pass both before and after
 the changes in 19623.03.patch.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/19623#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list