From 5c306d5ca4e77acab3ed462bcb28d9864f3023c0 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 2 Apr 2010 04:05:01 +0000 Subject: [PATCH] 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: https://develop.svn.wordpress.org/trunk@13932 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment-template.php | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 6165f8c674..34db4330b6 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -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