--- a/wp/wp-includes/class-wp-walker.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/class-wp-walker.php Tue Dec 15 13:49:49 2020 +0100
@@ -135,25 +135,23 @@
$id_field = $this->db_fields['id'];
$id = $element->$id_field;
- //display this element
+ // Display this element.
$this->has_children = ! empty( $children_elements[ $id ] );
if ( isset( $args[0] ) && is_array( $args[0] ) ) {
$args[0]['has_children'] = $this->has_children; // Back-compat.
}
- $cb_args = array_merge( array( &$output, $element, $depth ), $args );
- call_user_func_array( array( $this, 'start_el' ), $cb_args );
+ $this->start_el( $output, $element, $depth, ...array_values( $args ) );
- // descend only when the depth is right and there are childrens for this element
- if ( ( $max_depth == 0 || $max_depth > $depth + 1 ) && isset( $children_elements[ $id ] ) ) {
+ // Descend only when the depth is right and there are childrens for this element.
+ if ( ( 0 == $max_depth || $max_depth > $depth + 1 ) && isset( $children_elements[ $id ] ) ) {
foreach ( $children_elements[ $id ] as $child ) {
if ( ! isset( $newlevel ) ) {
$newlevel = true;
- //start the child delimiter
- $cb_args = array_merge( array( &$output, $depth ), $args );
- call_user_func_array( array( $this, 'start_lvl' ), $cb_args );
+ // Start the child delimiter.
+ $this->start_lvl( $output, $depth, ...array_values( $args ) );
}
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
}
@@ -161,14 +159,12 @@
}
if ( isset( $newlevel ) && $newlevel ) {
- //end the child delimiter
- $cb_args = array_merge( array( &$output, $depth ), $args );
- call_user_func_array( array( $this, 'end_lvl' ), $cb_args );
+ // End the child delimiter.
+ $this->end_lvl( $output, $depth, ...array_values( $args ) );
}
- //end this element
- $cb_args = array_merge( array( &$output, $element, $depth ), $args );
- call_user_func_array( array( $this, 'end_el' ), $cb_args );
+ // End this element.
+ $this->end_el( $output, $element, $depth, ...array_values( $args ) );
}
/**
@@ -181,23 +177,25 @@
* $max_depth > 0 specifies the number of display levels.
*
* @since 2.1.0
+ * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
+ * to the function signature.
*
* @param array $elements An array of elements.
* @param int $max_depth The maximum hierarchical depth.
+ * @param mixed ...$args Optional additional arguments.
* @return string The hierarchical item output.
*/
- public function walk( $elements, $max_depth ) {
- $args = array_slice( func_get_args(), 2 );
+ public function walk( $elements, $max_depth, ...$args ) {
$output = '';
- //invalid parameter or nothing to walk
+ // Invalid parameter or nothing to walk.
if ( $max_depth < -1 || empty( $elements ) ) {
return $output;
}
$parent_field = $this->db_fields['parent'];
- // flat display
+ // Flat display.
if ( -1 == $max_depth ) {
$empty_array = array();
foreach ( $elements as $e ) {
@@ -250,7 +248,7 @@
* If we are displaying all levels, and remaining children_elements is not empty,
* then we got orphans, which should be displayed regardless.
*/
- if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
+ if ( ( 0 == $max_depth ) && count( $children_elements ) > 0 ) {
$empty_array = array();
foreach ( $children_elements as $orphans ) {
foreach ( $orphans as $op ) {
@@ -273,19 +271,21 @@
* $max_depth > 0 specifies the number of display levels.
*
* @since 2.7.0
+ * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
+ * to the function signature.
*
* @param array $elements
* @param int $max_depth The maximum hierarchical depth.
- * @param int $page_num The specific page number, beginning with 1.
+ * @param int $page_num The specific page number, beginning with 1.
* @param int $per_page
+ * @param mixed ...$args Optional additional arguments.
* @return string XHTML of the specified page of elements
*/
- public function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
+ public function paged_walk( $elements, $max_depth, $page_num, $per_page, ...$args ) {
if ( empty( $elements ) || $max_depth < -1 ) {
return '';
}
- $args = array_slice( func_get_args(), 4 );
$output = '';
$parent_field = $this->db_fields['parent'];
@@ -295,7 +295,7 @@
$total_top = count( $elements );
}
if ( $page_num < 1 || $per_page < 0 ) {
- // No paging
+ // No paging.
$paging = false;
$start = 0;
if ( -1 == $max_depth ) {
@@ -311,7 +311,7 @@
}
}
- // flat display
+ // Flat display.
if ( -1 == $max_depth ) {
if ( ! empty( $args[0]['reverse_top_level'] ) ) {
$elements = array_reverse( $elements );
@@ -425,7 +425,7 @@
* @since 2.7.0
*
* @param object $e
- * @param array $children_elements
+ * @param array $children_elements
*/
public function unset_children( $e, &$children_elements ) {
if ( ! $e || ! $children_elements ) {
@@ -444,4 +444,4 @@
unset( $children_elements[ $id ] );
}
-} // Walker
+}