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. git-svn-id: https://develop.svn.wordpress.org/trunk@34454 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b23a1fc613
commit
e6b7c6b2d4
@ -433,10 +433,13 @@ function comment_class( $class = '', $comment = null, $post_id = null, $echo = t
|
||||
function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
|
||||
global $comment_alt, $comment_depth, $comment_thread_alt;
|
||||
|
||||
$comment = get_comment($comment_id);
|
||||
|
||||
$classes = array();
|
||||
|
||||
$comment = get_comment( $comment_id );
|
||||
if ( ! $comment ) {
|
||||
return $classes;
|
||||
}
|
||||
|
||||
// Get the comment type (comment, trackback),
|
||||
$classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
|
||||
|
||||
|
@ -36,4 +36,11 @@ class Tests_Comment_GetCommentClass extends WP_UnitTestCase {
|
||||
$this->assertContains( 'foo', $classes );
|
||||
$this->assertContains( 'bar', $classes );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33947
|
||||
*/
|
||||
public function test_should_return_an_empty_array_for_invalid_comment_id() {
|
||||
$this->assertSame( array(), get_comment_class( 'foo', 12345 ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user