Comments: Introduce a method for commenters to opt-in to receiving an email notification when their moderated comment gets approved.

The opt-in form is shown after the comment is submitted and held for moderation.

Sorry this took five years.

Props jeffr0, swissspidy, mrahmadawais, wonderboymusic, jdgrimes, obenland, Monika, imath, garrett-eclipse, johnbillion

Fixes #33717


git-svn-id: https://develop.svn.wordpress.org/trunk@50109 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2021-01-31 12:48:24 +00:00
parent 6ef5edd41f
commit e978de5a8d
5 changed files with 313 additions and 45 deletions

View File

@@ -554,6 +554,58 @@ class Tests_Comment extends WP_UnitTestCase {
return $notify_message;
}
/**
* @ticket 33717
*/
public function test_wp_new_comment_notify_comment_author_once_only() {
$c = self::factory()->comment->create(
array(
'comment_post_ID' => self::$post_id,
'comment_approved' => '0',
'comment_author_email' => 'foo@bar.mail',
)
);
// The comment author subscribed to receive an email once comment is approved.
update_comment_meta( $c, '_wp_comment_author_notification_optin', true );
// For the purpose of the test we are removing this hook to directly use the function to notify the comment author.
remove_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' );
// Approve the comment.
wp_set_comment_status( $c, 'approve' );
$sent = wp_new_comment_notify_comment_author( $c );
$resent = wp_new_comment_notify_comment_author( $c );
$this->assertTrue( $sent );
$this->assertFalse( $resent );
}
/**
* @ticket 33717
*/
public function test_wp_new_comment_notify_comment_author_has_not_opted_in() {
$c = self::factory()->comment->create(
array(
'comment_post_ID' => self::$post_id,
'comment_approved' => '0',
'comment_author_email' => 'bat@man.mail',
)
);
// For the purpose of the test we are removing this hook to directly use the function to notify the comment author.
remove_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' );
// Approve the comment.
wp_set_comment_status( $c, 'approve' );
$sent = wp_new_comment_notify_comment_author( $c );
// The comment author hasn't subscribed to receive an email, no email should be sent.
$this->assertFalse( $sent );
}
/**
* @ticket 12431
*/