Don't notify post authors about spam comments.

[34106] moved post author notification to a hook, and in the process, missed
the 'spam' check. This changeset restores that check.

To make unit testing easier, the notification callbacks have been refactored
to return values: false when various conditions aren't met (eg, approved
comments should not trigger moderation emails), and the return value of the
`wp_notify_*()` function otherwise.

Props cfinke, kraftbj.
See #33587.
Built from https://develop.svn.wordpress.org/trunk@34250


git-svn-id: http://core.svn.wordpress.org/trunk@34214 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-09-16 22:00:25 +00:00
parent a1050a58dc
commit f6fb4653eb
2 changed files with 17 additions and 5 deletions

View File

@ -1648,11 +1648,15 @@ function wp_new_comment( $commentdata ) {
*
* @param int $comment_ID ID of the comment.
* @param int $comment_approved Whether the comment is approved.
* @return bool True on success, false on failure.
*/
function wp_new_comment_notify_moderator( $comment_ID, $comment_approved ) {
if ( '0' == $comment_approved ) {
wp_notify_moderator( $comment_ID );
// Only send notifications for pending comments.
if ( '0' != $comment_approved ) {
return false;
}
return wp_notify_moderator( $comment_ID );
}
/**
@ -1661,6 +1665,7 @@ function wp_new_comment_notify_moderator( $comment_ID, $comment_approved ) {
* @since 4.4.0
*
* @param int $comment_ID ID of the comment.
* @return bool True on success, false on failure.
*/
function wp_new_comment_notify_postauthor( $comment_ID ) {
$comment = get_comment( $comment_ID );
@ -1669,9 +1674,16 @@ function wp_new_comment_notify_postauthor( $comment_ID ) {
* `wp_notify_postauthor()` checks if notifying the author of their own comment.
* By default, it won't, but filters can override this.
*/
if ( get_option( 'comments_notify' ) && $comment->comment_approved ) {
wp_notify_postauthor( $comment_ID );
if ( ! get_option( 'comments_notify' ) ) {
return false;
}
// Only send notifications for approved comments.
if ( 'spam' === $comment->comment_approved || ! $comment->comment_approved ) {
return false;
}
return wp_notify_postauthor( $comment_ID );
}
/**

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34249';
$wp_version = '4.4-alpha-34250';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.