From 68af5620776be84e1f340727c1da44251fac219d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 22 Jun 2021 19:09:00 +0000 Subject: [PATCH] Code Modernization: Use a consistent check for parent items in `WP_Walker`. This affects the `::walk()`, `::paged_walk()`, and `::get_number_of_root_elements()` methods. PHP 8 changes the way string to number comparisons are performed: https://wiki.php.net/rfc/string_to_number_comparison In particular, checking if an empty string is equal to zero in PHP 8 evaluates to `false`, not `true`. For the `WP_Walker` class, this resulted in an incorrect handling of parent items in a few methods. By explicitly checking for an `empty()` value instead, we make sure the check works as expected in PHP 8 and earlier versions. Follow-up to [35876], [48960], [49043], [49076]. Props sunxiyuan, aristath, SergeyBiryukov. Fixes #53474. Built from https://develop.svn.wordpress.org/trunk@51204 git-svn-id: http://core.svn.wordpress.org/trunk@50813 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-walker.php | 4 ++-- wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-walker.php b/wp-includes/class-wp-walker.php index 13c0b23429..c76451cd94 100644 --- a/wp-includes/class-wp-walker.php +++ b/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/wp-includes/version.php b/wp-includes/version.php index 0bf23f7b33..7108295a72 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-beta2-51203'; +$wp_version = '5.8-beta2-51204'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.