diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 2b2e3379c7..9d0bbe3fd4 100644
--- a/src/wp-includes/functions.php
+++ b/src/wp-includes/functions.php
@@ -2081,23 +2081,68 @@ function wp_mkdir_p( $target ) {
 		$dir_perms = 0777;
 	}
 
-	if ( @mkdir( $target, $dir_perms, true ) ) {
+	/*
+	 * FOR ILLUSTRATION PURPOSES ONLY - DO NOT MERGE THIS PATCH
+	 */
 
-		/*
-		 * If a umask is set that modifies $dir_perms, we'll have to re-set
-		 * the $dir_perms correctly with chmod()
-		 */
-		if ( ( $dir_perms & ~umask() ) !== $dir_perms ) {
-			$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
-			for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
-				chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
+	/*
+	 * If a umask is set that modifies $dir_perms, we'll have to re-set
+	 * the $dir_perms correctly with chmod()
+	 */
+	if ( ( $dir_perms & ~umask() ) !== $dir_perms ) {
+		$is_chmod_required = true;
+	} else {
+		$is_chmod_required = false;
+	}
+
+	/*
+	 * We cannot use mkdir()'s own built-in recursive functionality
+	 * (when the third argument is true) because it returns an error
+	 * if the directory already exists.
+	 * See https://core.trac.wordpress.org/ticket/60855.
+	 */
+
+	$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
+	for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
+		$intermediate_dir = $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) );
+		if ( @mkdir( $intermediate_dir ) ) {
+			/*
+			 * The mkdir() call succeeded - set permissions if necessary and continue.
+			 */
+			if ( $is_chmod_required ) {
+				chmod( $intermediate_dir, $dir_perms );
+			}
+			continue;
+		} else {
+			/*
+			 * The mkdir() call failed - try to find out why.
+			 */
+			if ( file_exists( $intermediate_dir ) ) {
+				/*
+				 * It seems that $intermediate_dir already exists.
+				 * If it's a directory, we can simply proceed to the next iteration.
+				 * If it's not a directory, then return failure.
+				 */
+				if ( is_dir( $intermediate_dir ) ) {
+					continue;
+				} else {
+					return false;
+				}
+			} else {
+				/*
+				 * It seems that $intermediate_dir does not exist.
+				 * Return failure.
+				 */
+				return false;
 			}
 		}
-
-		return true;
 	}
 
-	return false;
+	/*
+	 * If we get here, mkdir() was able to create all intermediate directories.
+	 * Return success.
+	 */
+	return true;
 }
 
 /**
