Opened 7 years ago
Last modified 6 years ago
#43298 assigned enhancement
Add filter to hide comment types from showing up in the default query
Reported by: | atimmer | Owned by: | schlessera |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | has-patch has-unit-tests 2nd-opinion |
Focuses: | Cc: |
Description
Comment types are not something WordPress supports by default. However, there is some data and API support for it. The wp_comments
table contains a comment_type
column which can be used for this purpose. The big downside is that by default these will be shown in all comment overview. Both on the frontend and the backend.
There are plugins that already do this. The examples that triggered this ticket are WooCommerce and this PR on Gutenberg. These plugins use the where
clause in the pieces of the query to make this possible.
I propose we add a 'simple' filter that can hide specific comment types from view. If comment_type
is not queried in any other way, this blacklist will make sure that all comment types in the blacklist are not returned from the query.
Why not wait for full comment_type support?
Full comment_type
support is a much bigger effort. This filter would benefit us in the short run and doesn't conflict with full comment_type
support.
I've uploaded an initial implementation of this filter.
Some notes:
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.WP_Comment_Query
. I added a public static function toWP_Comment_Query
to generate a filteringWHERE
clause, that these counting functions then use. This keeps the actual logic (and the filter definition) isolated within theWP_Comment_Query
class. Another option would of course be to reuse theWP_Comment_Query
directly for the counting functions, but I suppose this was not done for performance reasons.