Make WordPress Core


Ignore:
Timestamp:
06/24/2014 05:05:56 PM (12 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.