Make WordPress Core


Ignore:
Timestamp:
12/26/2015 05:23:43 AM (11 years ago)
Author:
dd32
Message:

Allow map_deep() to work with object properties containing a reference. Restores the previous behaviour of stripslashes_deep().

Merges [36100] to the 4.4 branch.
Props jeff@…, swissspidy.
See #22300, [35252].
Fixes #35058.

Location:
branches/4.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-includes/formatting.php

    r36098 r36101  
    38973897 */
    38983898function map_deep( $value, $callback ) {
    3899         if ( is_array( $value ) || is_object( $value ) ) {
    3900                 foreach ( $value as &$item ) {
    3901                         $item = map_deep( $item, $callback );
    3902                 }
    3903                 return $value;
     3899        if ( is_array( $value ) ) {
     3900                foreach ( $value as $index => $item ) {
     3901                        $value[ $index ] = map_deep( $item, $callback );
     3902                }
     3903        } elseif ( is_object( $value ) ) {
     3904                $object_vars = get_object_vars( $value );
     3905                foreach ( $object_vars as $property_name => $property_value ) {
     3906                        $value->$property_name = map_deep( $property_value, $callback );
     3907                }
    39043908        } else {
    3905                 return call_user_func( $callback, $value );
    3906         }
     3909                $value = call_user_func( $callback, $value );
     3910        }
     3911
     3912        return $value;
    39073913}
    39083914
Note: See TracChangeset for help on using the changeset viewer.