diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index 79b51c1a98..f8ebaecdcc 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -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; diff --git a/tests/phpunit/tests/comment/getCommentClass.php b/tests/phpunit/tests/comment/getCommentClass.php index c7ce64923b..5ca3bc41ea 100644 --- a/tests/phpunit/tests/comment/getCommentClass.php +++ b/tests/phpunit/tests/comment/getCommentClass.php @@ -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 ) ); + } }