Ticket #14041: 14041.2.diff
File 14041.2.diff, 4.5 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class-wp-walker.php
40 40 protected $max_pages = 1; 41 41 42 42 /** 43 * Wether the current element has children or not. To be used in start_el() 44 * 45 * @since 4.0.0 46 * @var bool 47 * @access protected 48 */ 49 protected $has_children; 50 51 /** 43 52 * Make private properties readable for backwards compatibility 44 53 * 45 54 * @since 4.0.0 … … 172 181 return; 173 182 174 183 $id_field = $this->db_fields['id']; 184 $id = $element->$id_field; 175 185 176 186 //display this element 177 if ( isset( $args[0] ) && is_array( $args[0] ) ) 178 $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] ); 187 $this->has_children = ! empty( $children_elements[ $id ] ); 188 if ( isset( $args[0] ) && is_array( $args[0] ) ) { 189 $args[0]['has_children'] = $this->has_children; // Backwards compatibility. 190 } 191 179 192 $cb_args = array_merge( array(&$output, $element, $depth), $args); 180 193 call_user_func_array(array($this, 'start_el'), $cb_args); 181 194 182 $id = $element->$id_field;183 184 195 // descend only when the depth is right and there are childrens for this element 185 196 if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) { 186 197 -
src/wp-includes/comment-template.php
1784 1784 $add_below = 'div-comment'; 1785 1785 } 1786 1786 ?> 1787 <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">1787 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '' ); ?> id="comment-<?php comment_ID(); ?>"> 1788 1788 <?php if ( 'div' != $args['style'] ) : ?> 1789 1789 <div id="div-comment-<?php comment_ID(); ?>" class="comment-body"> 1790 1790 <?php endif; ?> … … 1830 1830 protected function html5_comment( $comment, $depth, $args ) { 1831 1831 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; 1832 1832 ?> 1833 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>1833 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '' ); ?>> 1834 1834 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> 1835 1835 <footer class="comment-meta"> 1836 1836 <div class="comment-author vcard"> -
tests/phpunit/tests/comment/walker.php
1 <?php 2 3 /** 4 * @group comment 5 */ 6 class Tests_Comment_Walker extends WP_UnitTestCase { 7 8 function setUp() { 9 parent::setUp(); 10 11 $this->post_id = $this->factory->post->create(); 12 } 13 14 /** 15 * @ticket 14041 16 */ 17 function test_has_children() { 18 $comment_parent = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) ); 19 $comment_child = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_parent' => $comment_parent ) ); 20 $comment_parent = get_comment( $comment_parent ); 21 $comment_child = get_comment( $comment_child ); 22 23 $comment_walker = new Walker_Comment(); 24 $comment_callback = new Comment_Callback_Test( $this, $comment_walker ); 25 26 wp_list_comments( array( 'callback' => array( $comment_callback, 'comment' ), 'walker' => $comment_walker, 'echo' => false ), array( $comment_parent, $comment_child ) ); 27 wp_list_comments( array( 'callback' => array( $comment_callback, 'comment' ), 'walker' => $comment_walker, 'echo' => false ), array( $comment_child, $comment_parent ) ); 28 } 29 } 30 31 class Comment_Callback_Test { 32 public function __construct( Tests_Comment_Walker $test_walker, Walker_Comment $walker ) { 33 $this->test_walker = $test_walker; 34 $this->walker = $walker; 35 } 36 37 public function comment( $comment, $args, $depth ) { 38 if ( 1 == $depth ) { 39 $this->test_walker->assertTrue( $this->walker->has_children ); 40 $this->test_walker->assertTrue( $args['has_children'] ); // Back compat 41 } 42 43 else if ( 2 == $depth ) { 44 $this->test_walker->assertFalse( $this->walker->has_children ); 45 $this->test_walker->assertFalse( $args['has_children'] ); // Back compat 46 } 47 } 48 }