Fix out-of-order comments when comment nesting is reduced. Displays child comments on the same level after its "parent" in the case that the max_depth has been hit. See #8841
git-svn-id: http://svn.automattic.com/wordpress/trunk@13932 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
23a82e9619
commit
1d0b284a7c
|
@ -1266,6 +1266,70 @@ class Walker_Comment extends Walker {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function operates the same as Walker::display_element(), with one small change.
|
||||
* Instead of elements being moved to the end of the listing when their threading reaches
|
||||
* $max_depth, the children are displayed inline.
|
||||
*
|
||||
* Example: max_depth = 2, with 5 levels of nested content.
|
||||
* 1
|
||||
* 1.1
|
||||
* 1.1.1
|
||||
* 1.1.1.1
|
||||
* 1.1.1.1.1
|
||||
* 1.1.2
|
||||
* 1.1.2.1
|
||||
* 2
|
||||
* 2.2
|
||||
*
|
||||
*/
|
||||
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
|
||||
|
||||
if ( !$element )
|
||||
return;
|
||||
|
||||
$id_field = $this->db_fields['id'];
|
||||
|
||||
//display this element
|
||||
if ( is_array( $args[0] ) )
|
||||
$args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
|
||||
$cb_args = array_merge( array(&$output, $element, $depth), $args);
|
||||
call_user_func_array(array(&$this, 'start_el'), $cb_args);
|
||||
|
||||
$id = $element->$id_field;
|
||||
|
||||
// descend only when the depth is right and there are childrens for this element
|
||||
if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
|
||||
|
||||
foreach( $children_elements[ $id ] as $child ){
|
||||
|
||||
if ( !isset($newlevel) ) {
|
||||
$newlevel = true;
|
||||
//start the child delimiter
|
||||
$cb_args = array_merge( array(&$output, $depth), $args);
|
||||
call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
|
||||
}
|
||||
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
|
||||
}
|
||||
unset( $children_elements[ $id ] );
|
||||
} elseif ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
|
||||
// this elseif block is the only change from Walker::display_element()
|
||||
foreach( $children_elements[ $id ] as $child )
|
||||
$this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
|
||||
unset( $children_elements[ $id ] );
|
||||
}
|
||||
|
||||
if ( isset($newlevel) && $newlevel ){
|
||||
//end the child delimiter
|
||||
$cb_args = array_merge( array(&$output, $depth), $args);
|
||||
call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
|
||||
}
|
||||
|
||||
//end this element
|
||||
$cb_args = array_merge( array(&$output, $element, $depth), $args);
|
||||
call_user_func_array(array(&$this, 'end_el'), $cb_args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker::start_el()
|
||||
* @since unknown
|
||||
|
|
Loading…
Reference in New Issue