From 0802e754a2d9f61fc721e9a3d1c099c3c96accad Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Fri, 10 Jul 2020 00:29:48 +0000 Subject: [PATCH] Formatting: Ensure that wp_filter_object_list() will return an array when being passed an object with magic methods. Fixes #50095. Props johnjamesjacoby. git-svn-id: https://develop.svn.wordpress.org/trunk@48413 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-list-util.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/class-wp-list-util.php b/src/wp-includes/class-wp-list-util.php index 3b1d328447..a09b119f2c 100644 --- a/src/wp-includes/class-wp-list-util.php +++ b/src/wp-includes/class-wp-list-util.php @@ -102,12 +102,23 @@ class WP_List_Util { $filtered = array(); foreach ( $this->output as $key => $obj ) { - $to_match = (array) $obj; - $matched = 0; + foreach ( $args as $m_key => $m_value ) { - if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] ) { - $matched++; + + if ( is_array( $obj ) ) { + + // Treat object as an array + if ( array_key_exists( $m_key, $obj ) && ( $m_value == $obj[ $m_key ] ) ) { + $matched++; + } + + } elseif ( is_object( $obj ) ) { + + // Treat object as an object + if ( isset( $obj->{$m_key} ) && ( $m_value == $obj->{$m_key} ) ) { + $matched++; + } } }