diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
index 91690d8..3c688b9 100644
|
|
|
function sanitize_option( $option, $value ) {
|
| 3880 | 3880 | * @return The value with the callback applied to all non-arrays and non-objects inside it. |
| 3881 | 3881 | */ |
| 3882 | 3882 | function map_deep( $value, $callback ) { |
| 3883 | | if ( is_array( $value ) || is_object( $value ) ) { |
| 3884 | | foreach ( $value as &$item ) { |
| 3885 | | $item = map_deep( $item, $callback ); |
| | 3883 | if ( is_array( $value ) ) { |
| | 3884 | foreach ( $value as $index => $item ) { |
| | 3885 | $value[ $index ] = map_deep( $item, $callback ); |
| | 3886 | } |
| | 3887 | } elseif ( is_object( $value ) ) { |
| | 3888 | $object_vars = get_object_vars( $value ); |
| | 3889 | foreach ( $object_vars as $property_name => $property_value ) { |
| | 3890 | $value->$property_name = map_deep( $property_value, $callback ); |
| 3886 | 3891 | } |
| 3887 | | return $value; |
| 3888 | 3892 | } else { |
| 3889 | | return call_user_func( $callback, $value ); |
| | 3893 | $value = call_user_func( $callback, $value ); |
| 3890 | 3894 | } |
| | 3895 | |
| | 3896 | return $value; |
| 3891 | 3897 | } |
| 3892 | 3898 | |
| | 3899 | |
| 3893 | 3900 | /** |
| 3894 | 3901 | * Parses a string into variables to be stored in an array. |
| 3895 | 3902 | * |
diff --git tests/phpunit/tests/formatting/MapDeep.php tests/phpunit/tests/formatting/MapDeep.php
index 6fbd946..eb5914f 100644
|
|
|
class Tests_Formatting_MapDeep extends WP_UnitTestCase {
|
| 94 | 94 | ), array( $this, 'append_baba' ) ) ); |
| 95 | 95 | } |
| 96 | 96 | |
| | 97 | /** |
| | 98 | * @ticket 35058 |
| | 99 | */ |
| | 100 | public function test_map_deep_should_map_object_properties_passed_by_reference() { |
| | 101 | $object_a = (object) array( 'var0' => 'a' ); |
| | 102 | $object_b = (object) array( 'var0' => &$object_a->var0, 'var1' => 'x' ); |
| | 103 | $this->assertEquals( (object) array( |
| | 104 | 'var0' => 'ababa', |
| | 105 | 'var1' => 'xbaba', |
| | 106 | ), map_deep( $object_b, array( $this, 'append_baba' ) ) ); |
| | 107 | } |
| | 108 | |
| | 109 | /** |
| | 110 | * @ticket 35058 |
| | 111 | */ |
| | 112 | public function test_map_deep_should_map_array_elements_passed_by_reference() { |
| | 113 | $array_a = array( 'var0' => 'a' ); |
| | 114 | $array_b = array( 'var0' => &$array_a['var0'], 'var1' => 'x' ); |
| | 115 | $this->assertEquals( array( |
| | 116 | 'var0' => 'ababa', |
| | 117 | 'var1' => 'xbaba', |
| | 118 | ), map_deep( $array_b, array( $this, 'append_baba' ) ) ); |
| | 119 | } |
| | 120 | |
| 97 | 121 | public function append_baba( $value ) { |
| 98 | 122 | return $value . 'baba'; |
| 99 | 123 | } |