From 8853582220bbcfb786fb78f68afc4bc8071ef045 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Tue, 9 Nov 2021 01:10:59 +0000 Subject: [PATCH] General: Convert `wp_list_filter()` into a wrapper for `wp_filter_object_list()`. The code in `wp_list_filter()` was a duplicate of `wp_filter_object_list()`, minus the `WP_List_Util::pluck()` (used when `$field` is configured). In testing the wrapper, discovered an edge case (and potential bug) in `WP_List_Util::filter()` where if the operator matches an empty array was returned without resetting the output property. Without that property being set correctly, `WP_List_Util::get_output()` was not correct. This commit also fixes this by resetting the property to an empty array. Follow-up to [15686], [17427], [38928], [51044]. Props pbearne, sergeybiryukov, hellofromTonya. Fixes #53988. Built from https://develop.svn.wordpress.org/trunk@52066 git-svn-id: http://core.svn.wordpress.org/trunk@51658 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-list-util.php | 3 ++- wp-includes/functions.php | 9 ++------- wp-includes/version.php | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/wp-includes/class-wp-list-util.php b/wp-includes/class-wp-list-util.php index dfd44172b4..4df1dac357 100644 --- a/wp-includes/class-wp-list-util.php +++ b/wp-includes/class-wp-list-util.php @@ -102,7 +102,8 @@ class WP_List_Util { $operator = strtoupper( $operator ); if ( ! in_array( $operator, array( 'AND', 'OR', 'NOT' ), true ) ) { - return array(); + $this->output = array(); + return $this->output; } $count = count( $args ); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 667049aa3f..58d762df80 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -5047,6 +5047,7 @@ function wp_filter_object_list( $list, $args = array(), $operator = 'and', $fiel * * @since 3.1.0 * @since 4.7.0 Uses `WP_List_Util` class. + * @since 5.9.0 Converted into a wrapper for `wp_filter_object_list()`. * * @param array $list An array of objects to filter. * @param array $args Optional. An array of key => value arguments to match @@ -5058,13 +5059,7 @@ function wp_filter_object_list( $list, $args = array(), $operator = 'and', $fiel * @return array Array of found values. */ function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { - if ( ! is_array( $list ) ) { - return array(); - } - - $util = new WP_List_Util( $list ); - - return $util->filter( $args, $operator ); + return wp_filter_object_list( $list, $args, $operator ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 42082403bd..c8d40016cd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52065'; +$wp_version = '5.9-alpha-52066'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.