Ticket #33947: 33947.1.diff
File 33947.1.diff, 3.5 KB (added by , 10 years ago) |
---|
-
src/wp-includes/comment-template.php
433 433 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { 434 434 global $comment_alt, $comment_depth, $comment_thread_alt; 435 435 436 $comment = get_comment( $comment_id);436 $comment = get_comment( $comment_id ); 437 437 438 // Verify if comment is a WP_Comment object. 439 if ( ! $comment instanceof WP_Comment ) { 440 return array(); 441 } 442 438 443 $classes = array(); 439 444 440 445 // Get the comment type (comment, trackback), … … 441 446 $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type; 442 447 443 448 // Add classes for comment authors that are registered users. 444 if ( $comment->user_id > 0&& $user = get_userdata( $comment->user_id ) ) {449 if ( ! empty( $comment->user_id ) && $user = get_userdata( $comment->user_id ) ) { 445 450 $classes[] = 'byuser'; 446 451 $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id ); 447 452 // For comment authors who are the author of the post 448 if ( $post = get_post( $post_id) ) {453 if ( $post = get_post( $post_id ) ) { 449 454 if ( $comment->user_id === $post->post_author ) { 450 455 $classes[] = 'bypostauthor'; 451 456 } … … 452 457 } 453 458 } 454 459 455 if ( empty( $comment_alt) )460 if ( empty( $comment_alt ) ) { 456 461 $comment_alt = 0; 457 if ( empty($comment_depth) ) 462 } 463 464 if ( empty( $comment_depth ) ) { 458 465 $comment_depth = 1; 459 if ( empty($comment_thread_alt) ) 466 } 467 468 if ( empty( $comment_thread_alt ) ) { 460 469 $comment_thread_alt = 0; 470 } 461 471 462 472 if ( $comment_alt % 2 ) { 463 473 $classes[] = 'odd'; … … 481 491 482 492 $classes[] = "depth-$comment_depth"; 483 493 484 if ( !empty($class) ) { 485 if ( !is_array( $class ) ) 486 $class = preg_split('#\s+#', $class); 487 $classes = array_merge($classes, $class); 494 if ( ! empty( $class ) ) { 495 if ( ! is_array( $class ) ) { 496 $class = preg_split( '#\s+#', $class ); 497 } 498 $classes = array_merge( $classes, $class ); 488 499 } 489 500 490 $classes = array_map( 'esc_attr', $classes);501 $classes = array_map( 'esc_attr', $classes ); 491 502 492 503 /** 493 504 * Filter the returned CSS classes for the current comment. -
tests/phpunit/tests/comment/template.php
30 30 $this->assertEquals( 12, get_comments_number() ); 31 31 } 32 32 33 } 34 No newline at end of file 33 /** 34 * @ticket 33947 35 */ 36 public function test_get_comment_class_with_comment_id() { 37 $post_id = $this->factory->post->create(); 38 $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) ); 39 40 $classes1 = get_comment_class( array( 'test' ), $comment_id ); 41 $this->assertContains( 'test', $classes1 ); 42 $this->assertContains( 'comment', $classes1 ); 43 44 $classes2 = get_comment_class( 'test', $comment_id ); 45 $this->assertContains( 'test', $classes2 ); 46 $this->assertContains( 'comment', $classes2 ); 47 48 $obj_comment = get_comment( $comment_id ); 49 $classes3 = get_comment_class( 'test', $obj_comment ); 50 $this->assertContains( 'test', $classes3 ); 51 $this->assertContains( 'comment', $classes3 ); 52 53 wp_delete_comment( $comment_id, true ); 54 55 $classes4 = get_comment_class( 'test', $comment_id ); 56 $this->assertEquals( array(), $classes4 ); 57 } 58 59 }