Make WordPress Core

Changeset 52066


Ignore:
Timestamp:
11/09/2021 01:09:11 AM (2 years ago)
Author:
hellofromTonya
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-list-util.php

    r51044 r52066  
    103103
    104104        if ( ! in_array( $operator, array( 'AND', 'OR', 'NOT' ), true ) ) {
    105             return array();
     105            $this->output = array();
     106            return $this->output;
    106107        }
    107108
  • trunk/src/wp-includes/functions.php

    r52034 r52066  
    50485048 * @since 3.1.0
    50495049 * @since 4.7.0 Uses `WP_List_Util` class.
     5050 * @since 5.9.0 Converted into a wrapper for `wp_filter_object_list()`.
    50505051 *
    50515052 * @param array  $list     An array of objects to filter.
     
    50595060 */
    50605061function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
    5061     if ( ! is_array( $list ) ) {
    5062         return array();
    5063     }
    5064 
    5065     $util = new WP_List_Util( $list );
    5066 
    5067     return $util->filter( $args, $operator );
     5062    return wp_filter_object_list( $list, $args, $operator );
    50685063}
    50695064
Note: See TracChangeset for help on using the changeset viewer.