diff --git a/src/wp-includes/class-wp-walker.php b/src/wp-includes/class-wp-walker.php index 13c0b23429..c76451cd94 100644 --- a/src/wp-includes/class-wp-walker.php +++ b/src/wp-includes/class-wp-walker.php @@ -342,7 +342,7 @@ class Walker { $top_level_elements = array(); $children_elements = array(); foreach ( $elements as $e ) { - if ( 0 == $e->$parent_field ) { + if ( empty( $e->$parent_field ) ) { $top_level_elements[] = $e; } else { $children_elements[ $e->$parent_field ][] = $e; @@ -412,7 +412,7 @@ class Walker { $parent_field = $this->db_fields['parent']; foreach ( $elements as $e ) { - if ( 0 == $e->$parent_field ) { + if ( empty( $e->$parent_field ) ) { $num++; } } diff --git a/tests/phpunit/tests/walker.php b/tests/phpunit/tests/walker.php index 20b91df445..ea3ce16757 100644 --- a/tests/phpunit/tests/walker.php +++ b/tests/phpunit/tests/walker.php @@ -280,6 +280,36 @@ class Tests_Walker extends WP_UnitTestCase { } + /** + * @ticket 53474 + */ + function test_multiple_items_non_numeric_parent() { + + $items = array( + (object) array( + 'id' => 1, + 'parent' => '', + ), + (object) array( + 'id' => 2, + 'parent' => '', + ), + ); + $output = $this->walker->walk( $items, 0 ); + + $this->assertSame( 2, $this->walker->get_number_of_root_elements( $items ) ); + $this->assertSame( '<li>1</li><li>2</li>', $output ); + + $output = $this->walker->paged_walk( $items, 0, 1, 1 ); + + $this->assertSame( '<li>1</li>', $output ); + + $output = $this->walker->paged_walk( $items, 0, 2, 1 ); + + $this->assertSame( '<li>2</li>', $output ); + + } + } class Walker_Test extends Walker {