Make WordPress Core

Ticket #43805: 43805.3.diff

File 43805.3.diff, 5.7 KB (added by imath, 5 years ago)
  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index aa632921c6..60c8cfca0b 100644
    if ( ! function_exists( 'wp_notify_postauthor' ) ) : 
    16061606                                $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
    16071607                                /* translators: %s: Trackback/pingback/comment author URL. */
    16081608                                $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
     1609                                if ( 0 !== (int) $comment->comment_parent ) {
     1610                                        /* translators: Comment parent. 1: Comment parent URL */
     1611                                        $notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}" ) ) . "\r\n";
     1612                                }
    16091613                                /* translators: %s: Comment text. */
    16101614                                $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
    16111615                                $notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n";
    if ( ! function_exists( 'wp_notify_moderator' ) ) : 
    17811785                                $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
    17821786                                /* translators: %s: Trackback/pingback/comment author URL. */
    17831787                                $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
     1788                                if ( 0 !== (int) $comment->comment_parent ) {
     1789                                        /* translators: Comment parent. 1: Comment parent URL */
     1790                                        $notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}" ) ) . "\r\n";
     1791                                }
    17841792                                /* translators: %s: Comment text. */
    17851793                                $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
    17861794                                break;
  • tests/phpunit/tests/comment.php

    diff --git tests/phpunit/tests/comment.php tests/phpunit/tests/comment.php
    index 720a805062..6bf33b04db 100644
     
    66class Tests_Comment extends WP_UnitTestCase {
    77        protected static $user_id;
    88        protected static $post_id;
     9        protected static $notify_message;
    910
    1011        public function setUp() {
    1112                parent::setUp();
    class Tests_Comment extends WP_UnitTestCase { 
    434435                $this->assertFalse( $sent );
    435436        }
    436437
     438        /**
     439         * @ticket 43805
     440         */
     441        public function test_wp_new_comment_notify_postauthor_content_should_include_link_to_parent() {
     442                self::$notify_message = '';
     443
     444                $c = self::factory()->comment->create(
     445                        array(
     446                                'comment_post_ID'  => self::$post_id,
     447                        )
     448                );
     449
     450                $r = self::factory()->comment->create(
     451                        array(
     452                                'comment_post_ID'  => self::$post_id,
     453                                'comment_parent'   => $c,
     454                        )
     455                );
     456
     457                add_filter( 'comment_notification_text', array( $this, 'comment_notification_text_get' ), 10, 1 );
     458                $sent = wp_new_comment_notify_postauthor( $r );
     459                remove_filter( 'comment_notification_text', array( $this, 'comment_notification_text_get' ), 10, 1 );
     460
     461                $pattern = addcslashes( admin_url( "comment.php?action=editcomment&c={$c}" ), '/?&' );
     462
     463                $this->assertEquals( 1, preg_match( '/' . $pattern . '/', self::$notify_message ) );
     464        }
     465
     466        /**
     467         * @ticket 43805
     468         */
     469        public function test_wp_new_comment_notify_postauthor_content_shouldnot_include_link_to_parent() {
     470                self::$notify_message = '';
     471
     472                $c = self::factory()->comment->create(
     473                        array(
     474                                'comment_post_ID'  => self::$post_id,
     475                        )
     476                );
     477
     478                add_filter( 'comment_notification_text', array( $this, 'comment_notification_text_get' ), 10, 1 );
     479                $sent = wp_new_comment_notify_postauthor( $c );
     480                remove_filter( 'comment_notification_text', array( $this, 'comment_notification_text_get' ), 10, 1 );
     481
     482                $pattern = addcslashes( admin_url( "comment.php?action=editcomment&c={$c}" ), '/?&' );
     483
     484                $this->assertNotEquals( 1, preg_match( '/' . $pattern . '/', self::$notify_message ) );
     485        }
     486
     487        /**
     488         * @ticket 43805
     489         */
     490        public function test_wp_new_comment_notify_moderator_content_should_include_link_to_parent() {
     491                self::$notify_message = '';
     492
     493                $c = self::factory()->comment->create(
     494                        array(
     495                                'comment_post_ID'  => self::$post_id,
     496                        )
     497                );
     498
     499                $r = self::factory()->comment->create(
     500                        array(
     501                                'comment_post_ID'  => self::$post_id,
     502                                'comment_parent'   => $c,
     503                                'comment_approved' => '0',
     504                        )
     505                );
     506
     507                add_filter( 'comment_moderation_text', array( $this, 'comment_notification_text_get' ), 10, 1 );
     508                $sent = wp_new_comment_notify_moderator( $r );
     509                remove_filter( 'comment_moderation_text', array( $this, 'comment_notification_text_get' ), 10, 1 );
     510
     511                $pattern = addcslashes( admin_url( "comment.php?action=editcomment&c={$c}" ), '/?&' );
     512
     513                $this->assertEquals( 1, preg_match( '/' . $pattern . '/', self::$notify_message ) );
     514        }
     515
     516        /**
     517         * @ticket 43805
     518         */
     519        public function test_wp_new_comment_notify_moderator_content_shouldnot_include_link_to_parent() {
     520                self::$notify_message = '';
     521
     522                $c = self::factory()->comment->create(
     523                        array(
     524                                'comment_post_ID'  => self::$post_id,
     525                                'comment_approved' => '0'
     526                        )
     527                );
     528
     529                add_filter( 'comment_moderation_text', array( $this, 'comment_notification_text_get' ), 10, 1 );
     530                $sent = wp_new_comment_notify_moderator( $c );
     531                remove_filter( 'comment_moderation_text', array( $this, 'comment_notification_text_get' ), 10, 1 );
     532
     533                $pattern = addcslashes( admin_url( "comment.php?action=editcomment&c={$c}" ), '/?&' );
     534
     535                $this->assertNotEquals( 1, preg_match( '/' . $pattern . '/', self::$notify_message ) );
     536        }
     537
     538        /**
     539         * Callback for the `comment_notification_text` & `comment_moderation_text` filters.
     540         *
     541         * @param  string $notify_message The comment notification or moderation email text.
     542         * @return string
     543         */
     544        public function comment_notification_text_get( $notify_message = '' ) {
     545                self::$notify_message = $notify_message;
     546                return $notify_message;
     547        }
     548
    437549        /**
    438550         * @ticket 12431
    439551         */