wp/wp-includes/class-wp-walker.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
--- a/wp/wp-includes/class-wp-walker.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/class-wp-walker.php	Fri Sep 05 18:40:08 2025 +0200
@@ -11,6 +11,7 @@
  * @package WordPress
  * @abstract
  */
+#[AllowDynamicProperties]
 class Walker {
 	/**
 	 * What the class handles.
@@ -134,6 +135,9 @@
 			return;
 		}
 
+		$max_depth = (int) $max_depth;
+		$depth     = (int) $depth;
+
 		$id_field = $this->db_fields['id'];
 		$id       = $element->$id_field;
 
@@ -146,7 +150,7 @@
 		$this->start_el( $output, $element, $depth, ...array_values( $args ) );
 
 		// Descend only when the depth is right and there are children for this element.
-		if ( ( 0 == $max_depth || $max_depth > $depth + 1 ) && isset( $children_elements[ $id ] ) ) {
+		if ( ( 0 === $max_depth || $max_depth > $depth + 1 ) && isset( $children_elements[ $id ] ) ) {
 
 			foreach ( $children_elements[ $id ] as $child ) {
 
@@ -190,6 +194,8 @@
 	public function walk( $elements, $max_depth, ...$args ) {
 		$output = '';
 
+		$max_depth = (int) $max_depth;
+
 		// Invalid parameter or nothing to walk.
 		if ( $max_depth < -1 || empty( $elements ) ) {
 			return $output;
@@ -198,7 +204,7 @@
 		$parent_field = $this->db_fields['parent'];
 
 		// Flat display.
-		if ( -1 == $max_depth ) {
+		if ( -1 === $max_depth ) {
 			$empty_array = array();
 			foreach ( $elements as $e ) {
 				$this->display_element( $e, $empty_array, 1, 0, $args, $output );
@@ -234,7 +240,7 @@
 			$top_level_elements = array();
 			$children_elements  = array();
 			foreach ( $elements as $e ) {
-				if ( $root->$parent_field == $e->$parent_field ) {
+				if ( $root->$parent_field === $e->$parent_field ) {
 					$top_level_elements[] = $e;
 				} else {
 					$children_elements[ $e->$parent_field ][] = $e;
@@ -250,7 +256,7 @@
 		 * If we are displaying all levels, and remaining children_elements is not empty,
 		 * then we got orphans, which should be displayed regardless.
 		 */
-		if ( ( 0 == $max_depth ) && count( $children_elements ) > 0 ) {
+		if ( ( 0 === $max_depth ) && count( $children_elements ) > 0 ) {
 			$empty_array = array();
 			foreach ( $children_elements as $orphans ) {
 				foreach ( $orphans as $op ) {
@@ -284,23 +290,25 @@
 	 * @return string XHTML of the specified page of elements.
 	 */
 	public function paged_walk( $elements, $max_depth, $page_num, $per_page, ...$args ) {
+		$output = '';
+
+		$max_depth = (int) $max_depth;
+
 		if ( empty( $elements ) || $max_depth < -1 ) {
-			return '';
+			return $output;
 		}
 
-		$output = '';
-
 		$parent_field = $this->db_fields['parent'];
 
 		$count = -1;
-		if ( -1 == $max_depth ) {
+		if ( -1 === $max_depth ) {
 			$total_top = count( $elements );
 		}
 		if ( $page_num < 1 || $per_page < 0 ) {
 			// No paging.
 			$paging = false;
 			$start  = 0;
-			if ( -1 == $max_depth ) {
+			if ( -1 === $max_depth ) {
 				$end = $total_top;
 			}
 			$this->max_pages = 1;
@@ -308,13 +316,13 @@
 			$paging = true;
 			$start  = ( (int) $page_num - 1 ) * (int) $per_page;
 			$end    = $start + $per_page;
-			if ( -1 == $max_depth ) {
-				$this->max_pages = ceil( $total_top / $per_page );
+			if ( -1 === $max_depth ) {
+				$this->max_pages = (int) ceil( $total_top / $per_page );
 			}
 		}
 
 		// Flat display.
-		if ( -1 == $max_depth ) {
+		if ( -1 === $max_depth ) {
 			if ( ! empty( $args[0]['reverse_top_level'] ) ) {
 				$elements = array_reverse( $elements );
 				$oldstart = $start;
@@ -324,7 +332,7 @@
 
 			$empty_array = array();
 			foreach ( $elements as $e ) {
-				$count++;
+				++$count;
 				if ( $count < $start ) {
 					continue;
 				}
@@ -353,7 +361,7 @@
 
 		$total_top = count( $top_level_elements );
 		if ( $paging ) {
-			$this->max_pages = ceil( $total_top / $per_page );
+			$this->max_pages = (int) ceil( $total_top / $per_page );
 		} else {
 			$end = $total_top;
 		}
@@ -371,7 +379,7 @@
 		}
 
 		foreach ( $top_level_elements as $e ) {
-			$count++;
+			++$count;
 
 			// For the last page, need to unset earlier children in order to keep track of orphans.
 			if ( $end >= $total_top && $count < $start ) {
@@ -415,7 +423,7 @@
 
 		foreach ( $elements as $e ) {
 			if ( empty( $e->$parent_field ) ) {
-				$num++;
+				++$num;
 			}
 		}
 		return $num;
@@ -445,5 +453,4 @@
 
 		unset( $children_elements[ $id ] );
 	}
-
 }