From b24a140abe8285197b3cef20832bc663a7b35663 Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Tue, 21 Apr 2026 22:34:48 +0530 Subject: [PATCH 1/2] Enhance comment reply link functionality with depth limit argument and corresponding tests --- src/wp-includes/comment-template.php | 9 ++- .../tests/comment/getCommentReplyLink.php | 62 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index 0093f12d637e2..f8bf0a7a81d57 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -1725,6 +1725,7 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c * * @since 2.7.0 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. + * @since 4.9.0 Added the `$limit_by_depth` argument, whether to hide the link at the max depth and below. * * @param array $args { * Optional. Override default arguments. @@ -1746,6 +1747,7 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0. * @type string $before The text or HTML to add before the reply link. Default empty. * @type string $after The text or HTML to add after the reply link. Default empty. + * @type bool $limit_by_depth Hide the link at the max depth and below. Default true. * } * @param int|WP_Comment $comment Optional. Comment being replied to. Default current comment. * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. @@ -1765,6 +1767,7 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null 'before' => '', 'after' => '', 'show_reply_to_text' => false, + 'limit_by_depth' => true, ); $args = wp_parse_args( $args, $defaults ); @@ -1772,7 +1775,11 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null $args['max_depth'] = (int) $args['max_depth']; $args['depth'] = (int) $args['depth']; - if ( 0 === $args['depth'] || $args['max_depth'] <= $args['depth'] ) { + if ( 0 === $args['depth'] ) { + return null; + } + + if ( $args['limit_by_depth'] && $args['max_depth'] <= $args['depth'] ) { return null; } diff --git a/tests/phpunit/tests/comment/getCommentReplyLink.php b/tests/phpunit/tests/comment/getCommentReplyLink.php index 7bb4e91551d5d..e0877262dc895 100644 --- a/tests/phpunit/tests/comment/getCommentReplyLink.php +++ b/tests/phpunit/tests/comment/getCommentReplyLink.php @@ -87,4 +87,66 @@ public function test_should_return_null_when_depth_less_than_max_depth_and_comme $this->assertNull( $actual ); } + + /** + * @ticket 38925 + */ + public function test_should_return_reply_link_when_limit_by_depth_is_false_and_max_depth_less_than_depth() { + $post_id = self::factory()->post->create(); + $comment_id = self::factory()->comment->create( + array( + 'comment_post_ID' => $post_id, + 'comment_approved' => '1', + ) + ); + + $args = array( + 'depth' => 5, + 'max_depth' => 4, + 'limit_by_depth' => false, + ); + + $this->assertStringContainsString( 'replytocom', get_comment_reply_link( $args, $comment_id ) ); + } + + /** + * @ticket 38925 + */ + public function test_should_return_reply_link_when_limit_by_depth_is_true_and_depth_less_than_max_depth() { + $post_id = self::factory()->post->create(); + $comment_id = self::factory()->comment->create( + array( + 'comment_post_ID' => $post_id, + 'comment_approved' => '1', + ) + ); + + $args = array( + 'depth' => 4, + 'max_depth' => 5, + 'limit_by_depth' => true, + ); + + $this->assertStringContainsString( 'replytocom', get_comment_reply_link( $args, $comment_id ) ); + } + + /** + * @ticket 38925 + */ + public function test_should_return_false_on_post_with_closed_comment_status() { + $post_id = self::factory()->post->create( array( 'comment_status' => 'closed' ) ); + $comment_id = self::factory()->comment->create( + array( + 'comment_post_ID' => $post_id, + 'comment_approved' => '1', + ) + ); + + $args = array( + 'depth' => 4, + 'max_depth' => 5, + ); + + $this->assertFalse( get_comment_reply_link( $args, $comment_id ) ); + } } From 5d617237e9f98e06bd55153ae6c8f3f4ebc68e27 Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Tue, 21 Apr 2026 22:53:48 +0530 Subject: [PATCH 2/2] Fix formatting of comment_post_ID in comment reply link tests --- tests/phpunit/tests/comment/getCommentReplyLink.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/comment/getCommentReplyLink.php b/tests/phpunit/tests/comment/getCommentReplyLink.php index e0877262dc895..714c33bfe1ee2 100644 --- a/tests/phpunit/tests/comment/getCommentReplyLink.php +++ b/tests/phpunit/tests/comment/getCommentReplyLink.php @@ -95,7 +95,7 @@ public function test_should_return_reply_link_when_limit_by_depth_is_false_and_m $post_id = self::factory()->post->create(); $comment_id = self::factory()->comment->create( array( - 'comment_post_ID' => $post_id, + 'comment_post_ID' => $post_id, 'comment_approved' => '1', ) ); @@ -116,7 +116,7 @@ public function test_should_return_reply_link_when_limit_by_depth_is_true_and_de $post_id = self::factory()->post->create(); $comment_id = self::factory()->comment->create( array( - 'comment_post_ID' => $post_id, + 'comment_post_ID' => $post_id, 'comment_approved' => '1', ) ); @@ -137,7 +137,7 @@ public function test_should_return_false_on_post_with_closed_comment_status() { $post_id = self::factory()->post->create( array( 'comment_status' => 'closed' ) ); $comment_id = self::factory()->comment->create( array( - 'comment_post_ID' => $post_id, + 'comment_post_ID' => $post_id, 'comment_approved' => '1', ) );