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
This commit is contained in:
parent
18a6a047bd
commit
d65a4e6498
@ -1802,7 +1802,7 @@ function wp_new_comment_notify_postauthor( $comment_ID ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only send notifications for approved comments.
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,6 +293,25 @@ class Tests_Comment extends WP_UnitTestCase {
|
|||||||
$this->assertTrue( wp_notify_moderator( $c ) );
|
$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
|
* @ticket 33587
|
||||||
*/
|
*/
|
||||||
@ -306,6 +325,19 @@ class Tests_Comment extends WP_UnitTestCase {
|
|||||||
$this->assertFalse( $sent );
|
$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
|
* @ticket 12431
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user