#27140 closed feature request (wontfix)
possible bug in pre_comment_approved filter
Reported by: | realblueorange | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | |
Focuses: | Cc: |
Description
When using the pre_comment_approved filter, it seems the return value of 0 does not function. A return value of 'spam' does what can be expected.
This is what the codex says:
http://codex.wordpress.org/Plugin_API/Filter_Reference/pre_comment_approved
This is the code:
function check_for_spam( $approved, $commentdata ) { if( !empty( $commentdata['comment_author_url'] ) ) { return 0; // disapproved } return $approved; } add_filter('pre_comment_approved', 'check_for_spam', '99', 2);
Tested in WP 3.8.1, 2012 theme.
This code is in functions.php and when I add a comment with a URL filled in the comment makes it into the database and I receive a "Please moderate" e-mail.
I would think a return of 0 means that the comment is ignored, no e-mail is sent and it certainly is not in the database. Or am I wrong??
If I return 'spam' in stead of 0 everything works as expected. There is no e-mail and the comment is stored in the database, and can be found in the spam bin when in admin.
Change History (7)
#1
@
11 years ago
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed
- Version 3.8.1 deleted
#2
@
11 years ago
Ah, in that case I think the codex needs changing. 'Disapproved' suggests something different.
the wording "0 if the comment should be disapproved" might be clearer worded as "0 if the comment is unapproved".
Sorry for the mixup. I guess there is no bug, and this filter cannot be used to prevent the comment from making it into the database.
Isn't it an idea to have another returncode that has as an effect that the comment is totally disregarded? Or do I need to make another ticket for this (sorry, this is my first time on trac).
#3
@
11 years ago
- Resolution worksforme deleted
- Status changed from closed to reopened
- Type changed from defect (bug) to feature request
#4
follow-up:
↓ 5
@
11 years ago
- Resolution set to wontfix
- Status changed from reopened to closed
Ah, in that case I think the codex needs changing.
The Codex is a wiki that anyone can edit. Feel free to change it :)
Isn't it an idea to have another returncode that has as an effect that the comment is totally disregarded?
I don't think the pre_comment_approved
filter is the right thing to modify in this case. What you could do instead is mark the comment as "spam" if it doesn't meet the criteria you want, and then automatically delete spam comments on the wp_insert_comment
action. Or, you can store some marker to "delete just this comment" in a global variable that you can access in your later action.
It's not a perfect solution, but I think you'll find working with WordPress to be full of imperfect solutions that work well-enough.
sorry, this is my first time on trac
No worries — welcome to WordPress Trac!
#5
in reply to:
↑ 4
@
11 years ago
Replying to danielbachhuber:
Ah, in that case I think the codex needs changing.
The Codex is a wiki that anyone can edit. Feel free to change it :)
OK, will give that a shot.
Isn't it an idea to have another returncode that has as an effect that the comment is totally disregarded?
I don't think the
pre_comment_approved
filter is the right thing to modify in this case. What you could do instead is mark the comment as "spam" if it doesn't meet the criteria you want, and then automatically delete spam comments on thewp_insert_comment
action. Or, you can store some marker to "delete just this comment" in a global variable that you can access in your later action.
Thanks for the idea. I'll go that way. This filter sounded like the perfect place for such a thing, and after some googling I thought there might be a big demand for such a simple solution.
It's not a perfect solution, but I think you'll find working with WordPress to be full of imperfect solutions that work well-enough.
Oh, yes. But it still is a great system. I like it a lot.
sorry, this is my first time on trac
No worries — welcome to WordPress Trac!
Thanks.
#6
follow-up:
↓ 7
@
11 years ago
It is a bit odd that we don't have a means of discarding a comment completely. wp_insert_comment()
is called regardless of the return value of the pre_comment_approved
filter, and there's nothing else in wp-comments-post.php
or wp_new_comment()
that can be used to discard a comment without inserting it.
#7
in reply to:
↑ 6
@
11 years ago
Replying to johnbillion:
It is a bit odd that we don't have a means of discarding a comment completely.
wp_insert_comment()
is called regardless of the return value of thepre_comment_approved
filter, and there's nothing else inwp-comments-post.php
orwp_new_comment()
that can be used to discard a comment without inserting it.
I couldn't agree more. I would love to have this added to the core. It would make writing a spam checker so much easier. All you can do right now is wait for the comment to be inserted and delete it later on somewhere. Right now I am throwing a wp_die() when my criteria aren't met, but that doesn't seem like the way to go.
Returning "0" means the comment will be marked as unapproved and triggers the comment moderation email. "Unapproved" comments appear for you to either approve or mark as spam in the admin. If you do the former, then the comment will appear on the post.
Returning "spam" means the comment will be marked as spam. No comment moderation email will be sent.