Skip to content

Commit

Permalink
Comments: Avoid PHP notice in get_comment_reply_link() for null c…
Browse files Browse the repository at this point in the history
…omment.

If there is no global comment, or the input comment is null, return early to prevent warnings.

Fixes #41846
Props birgire, earnjam



git-svn-id: https://develop.svn.wordpress.org/trunk@46335 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
whyisjake committed Sep 27, 2019
1 parent 9e59d26 commit 4ffefc2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/wp-includes/comment-template.php
Expand Up @@ -1646,6 +1646,10 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null

$comment = get_comment( $comment );

if ( empty( $comment ) ) {
return;
}

if ( empty( $post ) ) {
$post = $comment->comment_post_ID;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/phpunit/tests/comment/getCommentReplyLink.php
Expand Up @@ -66,4 +66,24 @@ public function test_get_comment_reply_link_should_include_post_permalink() {

$this->assertContains( $expected_url, $comment_reply_link );
}

/**
* @ticket 41846
*/
public function test_should_return_null_when_depth_less_than_max_depth_and_comment_null_and_no_current_global_comment() {

// Let max depth be greater than depth and depth be non-zero.
$args = array(
'depth' => 1,
'max_depth' => 2,
);

// Make sure there's no global comment object.
add_filter( 'get_comment', '__return_null' );

$actual = get_comment_reply_link( $args );

$this->assertNull( $actual );
}

}

0 comments on commit 4ffefc2

Please sign in to comment.