WordPress.org

Make WordPress Core

Changeset 46335


Ignore:
Timestamp:
09/27/2019 02:45:49 PM (3 weeks ago)
Author:
whyisjake
Message:

Comments: Avoid PHP notice in get_comment_reply_link() for null comment.

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

Fixes #41846
Props birgire, earnjam

Location:
trunk
Files:
2 edited

Legend:

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

    r46090 r46335  
    16461646
    16471647    $comment = get_comment( $comment );
     1648
     1649    if ( empty( $comment ) ) {
     1650        return;
     1651    }
    16481652
    16491653    if ( empty( $post ) ) {
  • trunk/tests/phpunit/tests/comment/getCommentReplyLink.php

    r45787 r46335  
    6767        $this->assertContains( $expected_url, $comment_reply_link );
    6868    }
     69
     70    /**
     71     * @ticket 41846
     72     */
     73    public function test_should_return_null_when_depth_less_than_max_depth_and_comment_null_and_no_current_global_comment() {
     74
     75        // Let max depth be greater than depth and depth be non-zero.
     76        $args = array(
     77            'depth'     => 1,
     78            'max_depth' => 2,
     79        );
     80
     81        // Make sure there's no global comment object.
     82        add_filter( 'get_comment', '__return_null' );
     83
     84        $actual = get_comment_reply_link( $args );
     85
     86        $this->assertNull( $actual );
     87    }
     88
    6989}
Note: See TracChangeset for help on using the changeset viewer.