From 85718ebf9ae5e69f66da9661142ad171c5caa74b Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 26 Dec 2015 05:22:26 +0000 Subject: [PATCH] Allow `map_deep()` to work with object properties containing a reference. Restores the previous behaviour of `stripslashes_deep()`. Props jeff@pyebrook.com, swissspidy. See #22300, [35252]. Fixes #35058. Built from https://develop.svn.wordpress.org/trunk@36100 git-svn-id: http://core.svn.wordpress.org/trunk@36065 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 16 +++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 0f51a44b9c..1b31ad17f5 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -3884,14 +3884,20 @@ function sanitize_option( $option, $value ) { * @return The value with the callback applied to all non-arrays and non-objects inside it. */ function map_deep( $value, $callback ) { - if ( is_array( $value ) || is_object( $value ) ) { - foreach ( $value as &$item ) { - $item = map_deep( $item, $callback ); + if ( is_array( $value ) ) { + foreach ( $value as $index => $item ) { + $value[ $index ] = map_deep( $item, $callback ); + } + } elseif ( is_object( $value ) ) { + $object_vars = get_object_vars( $value ); + foreach ( $object_vars as $property_name => $property_value ) { + $value->$property_name = map_deep( $property_value, $callback ); } - return $value; } else { - return call_user_func( $callback, $value ); + $value = call_user_func( $callback, $value ); } + + return $value; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 3c77233c59..516a918b1b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36099'; +$wp_version = '4.5-alpha-36100'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.