WordPress.org

Make WordPress Core

Changeset 28824


Ignore:
Timestamp:
06/24/2014 05:05:56 PM (7 years ago)
Author:
wonderboymusic
Message:

Ensure that a has_children parameter is given to Walker::start_el().

Adds unit tests.

Props scribu, obenland.
Fixes #14041.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-walker.php

    r28524 r28824  
    4141
    4242    /**
     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    /**
    4352     * Make private properties readable for backwards compatibility
    4453     *
     
    173182
    174183        $id_field = $this->db_fields['id'];
     184        $id       = $element->$id_field;
    175185
    176186        //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
    179192        $cb_args = array_merge( array(&$output, $element, $depth), $args);
    180193        call_user_func_array(array($this, 'start_el'), $cb_args);
    181 
    182         $id = $element->$id_field;
    183194
    184195        // descend only when the depth is right and there are childrens for this element
  • trunk/src/wp-includes/comment-template.php

    r28813 r28824  
    17851785        }
    17861786?>
    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(); ?>">
    17881788        <?php if ( 'div' != $args['style'] ) : ?>
    17891789        <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
     
    18311831        $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
    18321832?>
    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' : '' ); ?>>
    18341834            <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
    18351835                <footer class="comment-meta">
Note: See TracChangeset for help on using the changeset viewer.