[wp-trac] [WordPress Trac] #43298: Add filter to hide comment types from showing up in the default query
WordPress Trac
noreply at wordpress.org
Mon Feb 19 10:17:13 UTC 2018
#43298: Add filter to hide comment types from showing up in the default query
-------------------------------------------------+-------------------------
Reporter: atimmer | Owner: schlessera
Type: enhancement | Status: assigned
Priority: normal | Milestone: Awaiting
Component: Comments | Review
Severity: normal | Version: trunk
Keywords: has-patch has-unit-tests 2nd- | Resolution:
opinion | Focuses:
-------------------------------------------------+-------------------------
Changes (by schlessera):
* keywords: => has-patch has-unit-tests 2nd-opinion
* owner: => schlessera
* status: new => assigned
Comment:
I've uploaded an initial implementation of this filter.
Some notes:
- The filter is meant to return an array of comment type strings.
- In the `WP_Comment_Query` class, if there's a conflict between
explicitly including a comment type and also trying to exclude it as well,
the inclusion takes precedence. This is to avoid instances where you query
a particular type, but get an empty result set because it was filtered out
by default in a different code path.
- There are counting functions that use their own SQL queries, instead of
relying on `WP_Comment_Query`. I added a public static function to
`WP_Comment_Query` to generate a filtering `WHERE` clause, that these
counting functions then use. This keeps the actual logic (and the filter
definition) isolated within the `WP_Comment_Query` class. Another option
would of course be to reuse the `WP_Comment_Query` directly for the
counting functions, but I suppose this was not done for performance
reasons.
- The patch includes tests that not only test whether the filtering is
working, but also whether it correctly bypasses caching if changed.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43298#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list