From 66937c7dcec860eaf1658871f13467435a470473 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 25 Feb 2023 10:59:22 +0000 Subject: [PATCH] General: Add more error checking to `WP_List_Util::pluck()`. Values for the input array in `WP_List_Util::pluck()` or `wp_list_pluck()` must be either objects or arrays. This commit adds a check to ensure that the value retrieved in the loop is an array before treating it as such, and throws a `_doing_it_wrong()` notice if it is neither an object nor an array. Follow-up to [14108], [15686], [18602], [28900], [38928]. Props afragen, costdev, audrasjb. Fixes #56650. Built from https://develop.svn.wordpress.org/trunk@55423 git-svn-id: http://core.svn.wordpress.org/trunk@54956 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-list-util.php | 16 ++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-list-util.php b/wp-includes/class-wp-list-util.php index 3648cd89f5..c394f2c613 100644 --- a/wp-includes/class-wp-list-util.php +++ b/wp-includes/class-wp-list-util.php @@ -166,8 +166,14 @@ class WP_List_Util { foreach ( $this->output as $key => $value ) { if ( is_object( $value ) ) { $newlist[ $key ] = $value->$field; - } else { + } elseif ( is_array( $value ) ) { $newlist[ $key ] = $value[ $field ]; + } else { + _doing_it_wrong( + __METHOD__, + __( 'Values for the input array must be either objects or arrays.' ), + '6.2.0' + ); } } @@ -187,12 +193,18 @@ class WP_List_Util { } else { $newlist[] = $value->$field; } - } else { + } elseif ( is_array( $value ) ) { if ( isset( $value[ $index_key ] ) ) { $newlist[ $value[ $index_key ] ] = $value[ $field ]; } else { $newlist[] = $value[ $field ]; } + } else { + _doing_it_wrong( + __METHOD__, + __( 'Values for the input array must be either objects or arrays.' ), + '6.2.0' + ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 0301dd9bfc..e0dfc0e382 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-beta3-55422'; +$wp_version = '6.2-beta3-55423'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.