WordPress.org

Make WordPress Core

Opened 4 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:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.1
Component: Plugins Keywords: has-patch
Focuses: 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 4 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)

sc0ttkclark4 years ago

Initial Patch including the new filters / actions

comment:1 sc0ttkclark4 years ago

#1 is now a filter as per @nacin

comment:2 sc0ttkclark4 years ago

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

comment:3 scribu3 years ago

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

comment:4 sc0ttkclark3 years ago

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?

comment:6 sc0ttkclark3 years ago

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

comment:7 scribu3 years ago

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

comment:8 sc0ttkclark3 years ago

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

sc0ttkclark3 years ago

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

comment:9 sc0ttkclark3 years ago

  • Keywords has-patch added

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

sc0ttkclark3 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

comment:10 sc0ttkclark3 years ago

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

sc0ttkclark3 years ago

Revised to use do_action_ref_array vs apply_filters_ref_array

comment:11 scribu3 years ago

  • Milestone changed from Awaiting Review to 3.1

comment:12 scribu3 years ago

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:13 scribu3 years ago

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

Note: See TracTickets for help on using tickets.