Make WordPress Core

Changeset 36119 for trunk


Ignore:
Timestamp:
12/29/2015 05:53:23 PM (11 years ago)
Author:
jorbin
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r36115 r36119  
    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        }
  • trunk/tests/phpunit/tests/comment.php

    r35853 r36119  
    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
     
    301320                        'comment_post_ID' => self::$post_id,
    302321                        'comment_approved' => 'spam',
     322                ) );
     323
     324                $sent = wp_new_comment_notify_postauthor( $c );
     325                $this->assertFalse( $sent );
     326        }
     327
     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',
    303335                ) );
    304336
Note: See TracChangeset for help on using the changeset viewer.