Make WordPress Core


Ignore:
Timestamp:
09/16/2015 09:59:16 PM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-functions.php

    r34161 r34250  
    16491649 * @param int $comment_ID       ID of the comment.
    16501650 * @param int $comment_approved Whether the comment is approved.
     1651 * @return bool True on success, false on failure.
    16511652 */
    16521653function wp_new_comment_notify_moderator( $comment_ID, $comment_approved ) {
    1653     if ( '0' == $comment_approved ) {
    1654         wp_notify_moderator( $comment_ID );
    1655     }
     1654    // Only send notifications for pending comments.
     1655    if ( '0' != $comment_approved ) {
     1656        return false;
     1657    }
     1658
     1659    return wp_notify_moderator( $comment_ID );
    16561660}
    16571661
     
    16621666 *
    16631667 * @param int $comment_ID ID of the comment.
     1668 * @return bool True on success, false on failure.
    16641669 */
    16651670function wp_new_comment_notify_postauthor( $comment_ID ) {
     
    16701675     * By default, it won't, but filters can override this.
    16711676     */
    1672     if ( get_option( 'comments_notify' ) && $comment->comment_approved ) {
    1673         wp_notify_postauthor( $comment_ID );
    1674     }
     1677    if ( ! get_option( 'comments_notify' ) ) {
     1678        return false;
     1679    }
     1680
     1681    // Only send notifications for approved comments.
     1682    if ( 'spam' === $comment->comment_approved || ! $comment->comment_approved ) {
     1683        return false;
     1684    }
     1685
     1686    return wp_notify_postauthor( $comment_ID );
    16751687}
    16761688
Note: See TracChangeset for help on using the changeset viewer.