From 462b6016b7385e098db57379f7506ff7ddddbd2e Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 2 Jan 2016 03:34:35 +0000 Subject: [PATCH] Comments: Ensure only approved comments trigger post author notifications Posts that are trashed shouldn't trigger post author notifications. Adds unit tests to enforce this. Merges [36119] to the 4.4 branch. Props scottbrownconsulting, peterwilsoncc, swissspidy. Fixes #35006. git-svn-id: https://develop.svn.wordpress.org/branches/4.4@36146 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment.php | 2 +- tests/phpunit/tests/comment.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 61b34b758e..9586b8b745 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -1805,7 +1805,7 @@ function wp_new_comment_notify_postauthor( $comment_ID ) { } // Only send notifications for approved comments. - if ( ! isset( $comment->comment_approved ) || 'spam' === $comment->comment_approved || ! $comment->comment_approved ) { + if ( ! isset( $comment->comment_approved ) || '1' != $comment->comment_approved ) { return false; } diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index 4fd1df119e..96ad409991 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -278,6 +278,25 @@ class Tests_Comment extends WP_UnitTestCase { $this->assertTrue( wp_notify_moderator( $c ) ); } + public function test_wp_new_comment_notify_postauthor_should_send_email_when_comment_is_approved() { + $c = self::factory()->comment->create( array( + 'comment_post_ID' => self::$post_id, + ) ); + + $sent = wp_new_comment_notify_postauthor( $c ); + $this->assertTrue( $sent ); + } + + public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_is_unapproved() { + $c = self::factory()->comment->create( array( + 'comment_post_ID' => self::$post_id, + 'comment_approved' => '0', + ) ); + + $sent = wp_new_comment_notify_postauthor( $c ); + $this->assertFalse( $sent ); + } + /** * @ticket 33587 */ @@ -291,6 +310,19 @@ class Tests_Comment extends WP_UnitTestCase { $this->assertFalse( $sent ); } + /** + * @ticket 35006 + */ + public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_has_been_trashed() { + $c = self::factory()->comment->create( array( + 'comment_post_ID' => self::$post_id, + 'comment_approved' => 'trash', + ) ); + + $sent = wp_new_comment_notify_postauthor( $c ); + $this->assertFalse( $sent ); + } + /** * @ticket 12431 */