WordPress.org

Make WordPress Core

Changeset 48413


Ignore:
Timestamp:
07/10/2020 12:29:48 AM (3 months ago)
Author:
whyisjake
Message:

Formatting: Ensure that wp_filter_object_list() will return an array when being passed an object with magic methods.

Fixes #50095.

Props johnjamesjacoby.

File:
1 edited

Legend:

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

    r47808 r48413  
    103103
    104104        foreach ( $this->output as $key => $obj ) {
    105             $to_match = (array) $obj;
    106 
    107105            $matched = 0;
     106
    108107            foreach ( $args as $m_key => $m_value ) {
    109                 if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] ) {
    110                     $matched++;
     108
     109                if ( is_array( $obj ) ) {
     110
     111                    // Treat object as an array
     112                    if ( array_key_exists( $m_key, $obj ) && ( $m_value == $obj[ $m_key ] ) ) {
     113                        $matched++;
     114                    }
     115
     116                } elseif ( is_object( $obj ) ) {
     117
     118                    // Treat object as an object
     119                    if ( isset( $obj->{$m_key} ) && ( $m_value == $obj->{$m_key} ) ) {
     120                        $matched++;
     121                    }
    111122                }
    112123            }
Note: See TracChangeset for help on using the changeset viewer.