#35060 closed feature request (fixed)
Allow filtering of comment count
Reported by: | peterwilsoncc | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | 2.5 |
Component: | Comments | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
Adding a filter to wp_update_comment_count_now
would be handy. Use cases:
- sites collect comment types but don't display them
- not comment comments such as those used by edd and woo commerce.
Related #12668
Attachments (5)
Change History (23)
#3
@
9 years ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from Future Release to 4.5
#4
@
9 years ago
- Keywords needs-unit-tests added
@swissspidy that was my first thought too, but figured it might be best to avoid the DB call in the function if possible, see 35060.3.diff.
Unsure if the filter is documented properly with the null
constant.
No tests exist for wp_update_comment_count_now
, where are these best placed, does it need to be a seperate ticket?
#5
@
9 years ago
@peterwilsoncc A better name for the filter would probably be pre_wp_update_comment_count_now
since it happens before the DB call.
The unit tests should go in a new file: /tests/phpunit/tests/comment/wpUpdateCommentCountNow.php
#7
follow-up:
↓ 8
@
9 years ago
@swissspidy Curious why you are using null
as the default value of the wp_update_comment_count_now
filter? Is there any reason we should not just pass in the $new
comment count?
#8
in reply to:
↑ 7
@
9 years ago
Replying to rachelbaker:
@swissspidy Curious why you are using
null
as the default value of thewp_update_comment_count_now
filter? Is there any reason we should not just pass in the$new
comment count?
That was my suggestion, the intention is to avoid the extra database lookup if the filter returns a valid value. The query is uncached and comment_approved
is not indexed.
#9
@
9 years ago
@rachelbaker So..what do you think about this approach with null (or maybe false) as the default?
#10
@
9 years ago
@swissspidy Personally, I don't like the idea of using a filter to bail out of the query. I couldn't find another example of this within the codebase. Would an action be a better fit here?
#12
follow-up:
↓ 13
@
9 years ago
For what it's worth, the basis was the 'pre_option_' . $option
filter in get_option()
. I can't think where else something similar happens, though.
#13
in reply to:
↑ 12
@
9 years ago
Replying to peterwilsoncc:
For what it's worth, the basis was the
'pre_option_' . $option
filter inget_option()
. I can't think where else something similar happens, though.
$ ack "apply_filters\([^\,]+, null" src/
suggests a few places:
get_option()
get_site_by_path()
get_avatar()
get_metadata()
get_network_by_path()
The pattern is: if a pre_
filter allows developers to avoid expensive queries, then it's justified. I think it's reasonable in this case.
#14
@
9 years ago
- Keywords commit added; 2nd-opinion removed
35060.5.diff simplifies the patch and also fixes docblock formatting. Adds pre_
to the filter name.
@peterwilsoncc Sounds reasonable. Want to work up a patch?