Make WordPress Core

Changeset 34250


Ignore:
Timestamp:
09/16/2015 09:59:16 PM (11 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.

Location:
trunk
Files:
2 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
  • trunk/tests/phpunit/tests/comment.php

    r34172 r34250  
    260260                $this->assertTrue( wp_notify_moderator( $c ) );
    261261        }
     262
     263        /**
     264         * @ticket 33587
     265         */
     266        public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_has_been_marked_as_spam() {
     267                $p = $this->factory->post->create();
     268                $c = $this->factory->comment->create( array(
     269                        'comment_post_ID' => $p,
     270                        'comment_approved' => 'spam',
     271                ) );
     272
     273                $sent = wp_new_comment_notify_postauthor( $c );
     274                $this->assertFalse( $sent );
     275        }
    262276}
Note: See TracChangeset for help on using the changeset viewer.