Make WordPress Core

Opened 6 years ago

Last modified 5 years ago

#43298 assigned enhancement

Add filter to hide comment types from showing up in the default query

Reported by: atimmer's profile atimmer Owned by: schlessera's profile schlessera
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch has-unit-tests 2nd-opinion
Focuses: Cc:


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.

Attachments (1)

43298.patch (6.6 KB) - added by schlessera 6 years ago.

Download all attachments as: .zip

Change History (3)

6 years ago

#1 @schlessera
6 years ago

  • Keywords has-patch has-unit-tests 2nd-opinion added
  • Owner set to schlessera
  • Status changed from new to assigned

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.

#2 @pento
5 years ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.