Make WordPress Core

Changeset 34454


Ignore:
Timestamp:
09/23/2015 02:08:47 PM (9 years ago)
Author:
boonebgorges
Message:

Bail early when invalid ID is passed to get_comment_class().

This helps to avoid PHP notices later in the function.

Props walterebert, dipesh.kakadiya, DrewAPicture.
Fixes #33947.

Location:
trunk
Files:
2 edited

Legend:

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

    r34308 r34454  
    434434    global $comment_alt, $comment_depth, $comment_thread_alt;
    435435
    436     $comment = get_comment($comment_id);
    437 
    438436    $classes = array();
     437
     438    $comment = get_comment( $comment_id );
     439    if ( ! $comment ) {
     440        return $classes;
     441    }
    439442
    440443    // Get the comment type (comment, trackback),
  • trunk/tests/phpunit/tests/comment/getCommentClass.php

    r34453 r34454  
    3737        $this->assertContains( 'bar', $classes );
    3838    }
     39
     40    /**
     41     * @ticket 33947
     42     */
     43    public function test_should_return_an_empty_array_for_invalid_comment_id() {
     44        $this->assertSame( array(), get_comment_class( 'foo', 12345 ) );
     45    }
    3946}
Note: See TracChangeset for help on using the changeset viewer.