From feb0830c796c559e892ae330d6e626da0dd44951 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 13 Aug 2019 05:08:14 +0000 Subject: [PATCH] Comments: Include post permalink in comment reply link. Include the post's permalink when generating reply links in `get_comment_reply_link()` to account for comments displayed on index and archive pages. This reapplies [32786] which was inadvertently reverted in [42360]. Props justinahinon, donmhico. See #33383. Fixes #47174. git-svn-id: https://develop.svn.wordpress.org/trunk@45787 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment-template.php | 3 +- .../tests/comment/getCommentReplyLink.php | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index 190bb7ac13..3bae940dac 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -1697,7 +1697,8 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null 'replytocom' => $comment->comment_ID, 'unapproved' => false, 'moderation-hash' => false, - ) + ), + get_permalink( $post->ID ) ) ) . '#' . $args['respond_id'], $data_attribute_string, diff --git a/tests/phpunit/tests/comment/getCommentReplyLink.php b/tests/phpunit/tests/comment/getCommentReplyLink.php index a9645fc4aa..5ca395e610 100644 --- a/tests/phpunit/tests/comment/getCommentReplyLink.php +++ b/tests/phpunit/tests/comment/getCommentReplyLink.php @@ -26,4 +26,44 @@ class Tests_Comment_GetCommentReplyLink extends WP_UnitTestCase { $this->assertNull( get_comment_reply_link( $args ) ); } + + /** + * Ensure comment reply links include post permalink. + * + * @ticket 47174 + */ + public function test_get_comment_reply_link_should_include_post_permalink() { + // Create a sample post. + $post_id = self::factory()->post->create(); + + // Insert comment. + $comment_id = self::factory()->comment->create( + array( + 'comment_post_ID' => $post_id, + 'user_id' => 1, + ) + ); + + // `depth` and `max_depth` required for reply links to display. + $comment_reply_link = get_comment_reply_link( + array( + 'depth' => 1, + 'max_depth' => 5, + ), + $comment_id, + $post_id + ); + + $expected_url = esc_url( + add_query_arg( + array( + 'p' => $post_id, + 'replytocom' => $comment_id, + ), + home_url( '/#respond' ) + ) + ); + + $this->assertContains( $expected_url, $comment_reply_link ); + } }