diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
index 91690d8..3c688b9 100644
--- src/wp-includes/formatting.php
+++ src/wp-includes/formatting.php
@@ -3880,16 +3880,23 @@ 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;
 }
 
+
 /**
  * Parses a string into variables to be stored in an array.
  *
diff --git tests/phpunit/tests/formatting/MapDeep.php tests/phpunit/tests/formatting/MapDeep.php
index 6fbd946..eb5914f 100644
--- tests/phpunit/tests/formatting/MapDeep.php
+++ tests/phpunit/tests/formatting/MapDeep.php
@@ -94,6 +94,30 @@ class Tests_Formatting_MapDeep extends WP_UnitTestCase {
 		), array( $this, 'append_baba' ) ) );
 	}
 
+	/**
+	 * @ticket 35058
+	 */
+	public function test_map_deep_should_map_object_properties_passed_by_reference() {
+		$object_a = (object) array( 'var0' => 'a' );
+		$object_b = (object) array( 'var0' => &$object_a->var0, 'var1' => 'x' );
+		$this->assertEquals( (object) array(
+			'var0' => 'ababa',
+			'var1' => 'xbaba',
+		), map_deep( $object_b, array( $this, 'append_baba' ) ) );
+	}
+
+	/**
+	 * @ticket 35058
+	 */
+	public function test_map_deep_should_map_array_elements_passed_by_reference() {
+		$array_a = array( 'var0' => 'a' );
+		$array_b = array( 'var0' => &$array_a['var0'], 'var1' => 'x' );
+		$this->assertEquals( array(
+			'var0' => 'ababa',
+			'var1' => 'xbaba',
+		), map_deep( $array_b, array( $this, 'append_baba' ) ) );
+	}
+
 	public function append_baba( $value ) {
 		return $value . 'baba';
 	}
