Opened 16 years ago
Closed 16 years ago
#8150 closed defect (bug) (fixed)
walker class special case
Reported by: | hailin | Owned by: | |
---|---|---|---|
Milestone: | 2.7 | Priority: | normal |
Severity: | normal | Version: | 2.7 |
Component: | General | Keywords: | has-patch, tested, reporter-feedback |
Focuses: | Cc: |
Description
In function walk( $elements, $max_depth),
when none of the elements is top level (parent = 0)
we assume the first one must be root of the sub elements.
and get it as $root = $elements[0].
This implicitly assumes that the first index is 0.
In fact, in some cases, it can start with any integer.
It's observed that it can start with 2. When that happens,
walker will not construct any top level elements, end up treating
all as orphans.
The better and safe, way is to user array function:
$first = array_slice( $elements, 0, 1 );
$root = $first[0];
Attachments (1)
Change History (6)
#1
@
16 years ago
- Keywords has-patch tested added
- Milestone changed from 2.8 to 2.7
- Version set to 2.7
#2
@
16 years ago
- Keywords reporter-feedback added
The patch looks good.
It would be good to know what the user problem for this issue is though.
What can it affect the display of?
#3
@
16 years ago
The issues is that with calls such as:
wp_list_categories('use_desc_for_title=1&child_of=400052&title_li=')
It will produce array $elements (categories), and there is not a single element whose parent=0 since they are children of 400052.
Then it will be handled by:
/*
- when none of the elements is top level
- assume the first one must be root of the sub elements */
if ( empty($top_level_elements) )
....
Because $elements is an associative array, the key may not begin with 0.
I've observed a bug on a particular blog, in which case the first element's key is
- That caused the $root= $elements[0] to be NULL since the key 0 does not exist.
As a result, $top_level_elements are empty, and then every element is displayed as orphans. The correct results would be nested structure.
With this fix, they are displayed correctly. It's tested in both positive and negative cases.
patch