Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/wp-includes/comment-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -1765,14 +1767,19 @@ 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 );

$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;
}

Expand Down
62 changes: 62 additions & 0 deletions tests/phpunit/tests/comment/getCommentReplyLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
Loading