Make WordPress Core

Changeset 13939


Ignore:
Timestamp:
04/02/2010 05:33:18 AM (14 years ago)
Author:
dd32
Message:

Reduce Code duplication. Rely on parent class to do the heavy lifting, just tack the comment addition on the end. See #8841

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment-template.php

    r13938 r13939  
    12681268
    12691269    /**
    1270      * This function operates the same as Walker::display_element(), with one small change.
    1271      * Instead of elements being moved to the end of the listing when their threading reaches
    1272      * $max_depth, the children are displayed inline.
     1270     * This function is designed to enhance Walker::display_element() to
     1271     * display children of higher nesting levels than selected inline on
     1272     * the highest depth level displayed. This prevents them being orphaned
     1273     * at the end of the comment list.
    12731274     *
    12741275     * Example: max_depth = 2, with 5 levels of nested content.
     
    12901291
    12911292        $id_field = $this->db_fields['id'];
    1292 
    1293         //display this element
    1294         if ( is_array( $args[0] ) )
    1295             $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
    1296         $cb_args = array_merge( array(&$output, $element, $depth), $args);
    1297         call_user_func_array(array(&$this, 'start_el'), $cb_args);
    1298 
    12991293        $id = $element->$id_field;
    13001294
    1301         // descend only when the depth is right and there are childrens for this element
    1302         if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
    1303 
    1304             foreach( $children_elements[ $id ] as $child ){
    1305 
    1306                 if ( !isset($newlevel) ) {
    1307                     $newlevel = true;
    1308                     //start the child delimiter
    1309                     $cb_args = array_merge( array(&$output, $depth), $args);
    1310                     call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
    1311                 }
    1312                 $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
    1313             }
    1314             unset( $children_elements[ $id ] );
    1315         }
    1316 
    1317         if ( isset($newlevel) && $newlevel ){
    1318             //end the child delimiter
    1319             $cb_args = array_merge( array(&$output, $depth), $args);
    1320             call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
    1321         }
    1322 
    1323         //end this element
    1324         $cb_args = array_merge( array(&$output, $element, $depth), $args);
    1325         call_user_func_array(array(&$this, 'end_el'), $cb_args);
    1326 
     1295        parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
     1296
     1297        // If we're at the max depth, and the current element still has children, loop over those and display them at this level
     1298        // This is to prevent them being orphaned to the end of the list.
    13271299        if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
    1328             // this if block is the only change from Walker::display_element()
    1329             foreach ( $children_elements[ $id ]  as $child )
     1300            foreach ( $children_elements[ $id ] as $child )
    13301301                $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
     1302
    13311303            unset( $children_elements[ $id ] );
    13321304        }
Note: See TracChangeset for help on using the changeset viewer.