From cd9e0814e6e2b6c5f8fc854e90eaee1fb43fca12 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 17 Aug 2013 03:08:50 +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 git-svn-id: https://develop.svn.wordpress.org/trunk@25047 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index b6d741f477..51f2b8f69a 100644 --- a/src/wp-includes/functions.php +++ b/src/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; }