From 5eb1c819249973b718183578b4f90b9d5009c4ef Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 17 Aug 2013 03:09:11 +0000 Subject: [PATCH] Make use of the recursive option in mkdir() in wp_mkdir_p(). Avoids a bunch of silenced PHP Notices being logged. Fixes #23196 Built from https://develop.svn.wordpress.org/trunk@25047 git-svn-id: http://core.svn.wordpress.org/trunk@25034 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index b6d741f477..51f2b8f69a 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1336,19 +1336,23 @@ function wp_mkdir_p( $target ) { if ( file_exists( $target ) ) return @is_dir( $target ); - // Attempting to create the directory may clutter up our display. - if ( @mkdir( $target ) ) { - $stat = @stat( dirname( $target ) ); - $dir_perms = $stat['mode'] & 0007777; // Get the permission bits. - @chmod( $target, $dir_perms ); - return true; - } elseif ( is_dir( dirname( $target ) ) ) { - return false; + // We need to find the permissions of the parent folder that exists and inherit that. + $target_parent = dirname( $target ); + while ( '.' != $target_parent && ! is_dir( $target_parent ) ) { + $target_parent = dirname( $target_parent ); } - // If the above failed, attempt to create the parent node, then try again. - if ( ( $target != '/' ) && ( wp_mkdir_p( dirname( $target ) ) ) ) - return wp_mkdir_p( $target ); + // Get the permission bits. + if ( $target_parent && '.' != $target_parent ) { + $stat = @stat( $target_parent ); + $dir_perms = $stat['mode'] & 0007777; + } else { + $dir_perms = 0777; + } + + if ( @mkdir( $target, $dir_perms, true ) ) { + return true; + } return false; }