Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15019 closed enhancement (fixed)

Filters / Actions for get_comments

Reported by: sc0ttkclark Owned by:
Priority: normal Milestone: 3.1
Component: Plugins Version: 3.1
Severity: normal Keywords: has-patch
Cc:

Description

Currently in 3.1 (trunk) get_comments() has no filters or actions. I'd like to improve this by adding them following the same format as get_posts >> WP_Query::query uses. As you can see in my patch, it's very minimal, not too much going on here besides these main things:

  1. New action pre_get_comments to run similar to WP_Query::query pre_get_posts
  1. New filters / action for specific $post_where, $orderby, $oder, $limit (and some cache-enablers)
  1. New filter the_comments to modify what's returned in $comments similar to WP_Query::query the_posts

Attachments (4)

wp-includes-comment-filters.patch (1.9 KB) - added by sc0ttkclark 3 years ago.
Initial Patch including the new filters / actions
wp-includes-comment-filters-refresh.patch (1.3 KB) - added by sc0ttkclark 3 years ago.
Revised filters, after discussion with @scribu for best-practice methods
wp-includes-comment-filters-fixed.patch (2.9 KB) - added by sc0ttkclark 3 years ago.
Patch refreshed and revised with adjustments to the changes made by refresh - also fixed $post_where to be $where (for consistency) and resolved a bug with $author_email / $karma not adding a space before the AND in appending $where
wp-includes-comment-filters-fixed.2.patch (2.9 KB) - added by sc0ttkclark 3 years ago.
Revised to use do_action_ref_array vs apply_filters_ref_array

Download all attachments as: .zip

Change History (17)

Initial Patch including the new filters / actions

#1 is now a filter as per @nacin

Just wanted to check in and see if there was anything further needed from me to get this into 3.1?

Do we really need the 'comments_orderby_request' series?

More importantly, note that the trend in WP_Query is to pass all query statements at once: #14997

That was a straight copy / paste from another section, any idea what I should use as an example of the WP_Query for passing all query statements at once for filtering?

Must have been working with a previous revision ;) Will adjust all corresponding patches.

Also, please try to make patches relative to the root WP folder. Currently, they are relative to wp-includes.

Will do in the future, thanks for the best-practices update.

Revised filters, after discussion with @scribu for best-practice methods

  • Keywords has-patch added

Refreshed and revised after IRC discussion with @scribu for best-practice methods.

Patch refreshed and revised with adjustments to the changes made by refresh - also fixed $post_where to be $where (for consistency) and resolved a bug with $author_email / $karma not adding a space before the AND in appending $where

Attached new patch - Patch refreshed and revised with adjustments to the changes made by refresh - also fixed $post_where to be $where (for consistency) and resolved a bug with $author_email / $karma not adding a space before the AND in appending $where

Revised to use do_action_ref_array vs apply_filters_ref_array

  • Milestone changed from Awaiting Review to 3.1
  • Resolution set to fixed
  • Status changed from new to closed

(In [16019]) Add filters to WP_Comment_Query. Props sc0ttkclark. Fixes #15019

(In [16020]) Make comment clauses more similar to post clauses. See #15019

Note: See TracTickets for help on using tickets.