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
This commit is contained in:
parent
8ea2e04925
commit
68af562077
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue