Skip to content

Commit d65a4e6

Browse files
committed
Ensure only approved comments trigger post author notifications
Posts that are trashed shouldn't trigger post author notifications. Adds unit tests to enforce this. Props scottbrownconsulting, peterwilsoncc, swissspidy Fixes #35006 git-svn-id: https://develop.svn.wordpress.org/trunk@36119 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 18a6a04 commit d65a4e6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/wp-includes/comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ function wp_new_comment_notify_postauthor( $comment_ID ) {
18021802
}
18031803

18041804
// Only send notifications for approved comments.
1805-
if ( ! isset( $comment->comment_approved ) || 'spam' === $comment->comment_approved || ! $comment->comment_approved ) {
1805+
if ( ! isset( $comment->comment_approved ) || '1' != $comment->comment_approved ) {
18061806
return false;
18071807
}
18081808

tests/phpunit/tests/comment.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,25 @@ public function test_wp_notify_moderator_should_not_throw_notice_when_post_autho
293293
$this->assertTrue( wp_notify_moderator( $c ) );
294294
}
295295

296+
public function test_wp_new_comment_notify_postauthor_should_send_email_when_comment_is_approved() {
297+
$c = self::factory()->comment->create( array(
298+
'comment_post_ID' => self::$post_id,
299+
) );
300+
301+
$sent = wp_new_comment_notify_postauthor( $c );
302+
$this->assertTrue( $sent );
303+
}
304+
305+
public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_is_unapproved() {
306+
$c = self::factory()->comment->create( array(
307+
'comment_post_ID' => self::$post_id,
308+
'comment_approved' => '0',
309+
) );
310+
311+
$sent = wp_new_comment_notify_postauthor( $c );
312+
$this->assertFalse( $sent );
313+
}
314+
296315
/**
297316
* @ticket 33587
298317
*/
@@ -306,6 +325,19 @@ public function test_wp_new_comment_notify_postauthor_should_not_send_email_when
306325
$this->assertFalse( $sent );
307326
}
308327

328+
/**
329+
* @ticket 35006
330+
*/
331+
public function test_wp_new_comment_notify_postauthor_should_not_send_email_when_comment_has_been_trashed() {
332+
$c = self::factory()->comment->create( array(
333+
'comment_post_ID' => self::$post_id,
334+
'comment_approved' => 'trash',
335+
) );
336+
337+
$sent = wp_new_comment_notify_postauthor( $c );
338+
$this->assertFalse( $sent );
339+
}
340+
309341
/**
310342
* @ticket 12431
311343
*/

0 commit comments

Comments
 (0)