Make WordPress Core

Changeset 47114


Ignore:
Timestamp:
01/27/2020 04:31:48 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Comments: Add In reply to: %s parent comment link to new comment email notifications.

This information was previously available on the Moderate Comment screen in the admin, but was missing from moderation emails.

Props imath, danieltj, andraganescu, galbaras, SergeyBiryukov.
Fixes #43805. See #43429.

Location:
trunk
Files:
2 edited

Legend:

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

    r47086 r47114  
    15851585                                $subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title );
    15861586                                break;
     1587
    15871588                        case 'pingback':
    15881589                                /* translators: %s: Post title. */
     
    15981599                                $subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title );
    15991600                                break;
     1601
    16001602                        default: // Comments
    16011603                                /* translators: %s: Post title. */
     
    16071609                                /* translators: %s: Trackback/pingback/comment author URL. */
    16081610                                $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
     1611
     1612                                if ( $comment->comment_parent && user_can( $post->post_author, 'edit_comment', $comment->comment_parent ) ) {
     1613                                        /* translators: Comment moderation. %s: Parent comment edit URL. */
     1614                                        $notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ) . "\r\n";
     1615                                }
     1616
    16091617                                /* translators: %s: Comment text. */
    16101618                                $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
     
    16141622                                break;
    16151623                }
     1624
    16161625                $notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
    16171626                /* translators: %s: Comment URL. */
     
    17621771                                $notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n";
    17631772                                break;
     1773
    17641774                        case 'pingback':
    17651775                                /* translators: %s: Post title. */
     
    17721782                                $notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n";
    17731783                                break;
     1784
    17741785                        default: // Comments
    17751786                                /* translators: %s: Post title. */
     
    17821793                                /* translators: %s: Trackback/pingback/comment author URL. */
    17831794                                $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
     1795
     1796                                if ( $comment->comment_parent ) {
     1797                                        /* translators: Comment moderation. %s: Parent comment edit URL. */
     1798                                        $notify_message .= sprintf( __( 'In reply to: %s' ), admin_url( "comment.php?action=editcomment&c={$comment->comment_parent}#wpbody-content" ) ) . "\r\n";
     1799                                }
     1800
    17841801                                /* translators: %s: Comment text. */
    17851802                                $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
  • trunk/tests/phpunit/tests/comment.php

    r46586 r47114  
    77        protected static $user_id;
    88        protected static $post_id;
     9        protected static $notify_message = '';
    910
    1011        public function setUp() {
     
    433434                $sent = wp_new_comment_notify_postauthor( $c );
    434435                $this->assertFalse( $sent );
     436        }
     437
     438        /**
     439         * @ticket 43805
     440         */
     441        public function test_wp_new_comment_notify_postauthor_content_should_include_link_to_parent() {
     442                $c1 = self::factory()->comment->create(
     443                        array(
     444                                'comment_post_ID' => self::$post_id,
     445                        )
     446                );
     447
     448                $c2 = self::factory()->comment->create(
     449                        array(
     450                                'comment_post_ID' => self::$post_id,
     451                                'comment_parent'  => $c1,
     452                        )
     453                );
     454
     455                add_filter( 'comment_notification_text', array( $this, 'save_comment_notification_text' ) );
     456                wp_new_comment_notify_postauthor( $c2 );
     457                remove_filter( 'comment_notification_text', array( $this, 'save_comment_notification_text' ) );
     458
     459                $this->assertContains( admin_url( "comment.php?action=editcomment&c={$c1}" ), self::$notify_message );
     460        }
     461
     462        /**
     463         * @ticket 43805
     464         */
     465        public function test_wp_new_comment_notify_moderator_content_should_include_link_to_parent() {
     466                $c1 = self::factory()->comment->create(
     467                        array(
     468                                'comment_post_ID' => self::$post_id,
     469                        )
     470                );
     471
     472                $c2 = self::factory()->comment->create(
     473                        array(
     474                                'comment_post_ID'  => self::$post_id,
     475                                'comment_parent'   => $c1,
     476                                'comment_approved' => '0',
     477                        )
     478                );
     479
     480                add_filter( 'comment_moderation_text', array( $this, 'save_comment_notification_text' ) );
     481                wp_new_comment_notify_moderator( $c2 );
     482                remove_filter( 'comment_moderation_text', array( $this, 'save_comment_notification_text' ) );
     483
     484                $this->assertContains( admin_url( "comment.php?action=editcomment&c={$c1}" ), self::$notify_message );
     485        }
     486
     487        /**
     488         * Callback for the `comment_notification_text` & `comment_moderation_text` filters.
     489         *
     490         * @param string $notify_message The comment notification or moderation email text.
     491         * @return string
     492         */
     493        public function save_comment_notification_text( $notify_message = '' ) {
     494                self::$notify_message = $notify_message;
     495                return $notify_message;
    435496        }
    436497
Note: See TracChangeset for help on using the changeset viewer.