WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/31/2021 12:48:24 PM (4 weeks ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment.php

    r49603 r50109  
    553553        self::$notify_message = $notify_message;
    554554        return $notify_message;
     555    }
     556
     557    /**
     558     * @ticket 33717
     559     */
     560    public function test_wp_new_comment_notify_comment_author_once_only() {
     561        $c = self::factory()->comment->create(
     562            array(
     563                'comment_post_ID'      => self::$post_id,
     564                'comment_approved'     => '0',
     565                'comment_author_email' => 'foo@bar.mail',
     566            )
     567        );
     568
     569        // The comment author subscribed to receive an email once comment is approved.
     570        update_comment_meta( $c, '_wp_comment_author_notification_optin', true );
     571
     572        // For the purpose of the test we are removing this hook to directly use the function to notify the comment author.
     573        remove_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' );
     574
     575        // Approve the comment.
     576        wp_set_comment_status( $c, 'approve' );
     577
     578        $sent = wp_new_comment_notify_comment_author( $c );
     579        $resent = wp_new_comment_notify_comment_author( $c );
     580
     581        $this->assertTrue( $sent );
     582        $this->assertFalse( $resent );
     583    }
     584
     585    /**
     586     * @ticket 33717
     587     */
     588    public function test_wp_new_comment_notify_comment_author_has_not_opted_in() {
     589        $c = self::factory()->comment->create(
     590            array(
     591                'comment_post_ID'      => self::$post_id,
     592                'comment_approved'     => '0',
     593                'comment_author_email' => 'bat@man.mail',
     594            )
     595        );
     596
     597        // For the purpose of the test we are removing this hook to directly use the function to notify the comment author.
     598        remove_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_comment_author' );
     599
     600        // Approve the comment.
     601        wp_set_comment_status( $c, 'approve' );
     602
     603        $sent = wp_new_comment_notify_comment_author( $c );
     604
     605        // The comment author hasn't subscribed to receive an email, no email should be sent.
     606        $this->assertFalse( $sent );
    555607    }
    556608
Note: See TracChangeset for help on using the changeset viewer.