From 52c8975ba6b68278c49274453e011ecab11d9054 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 1 Apr 2014 04:01:10 +0000 Subject: [PATCH] Fix a regression in wp_mkdir_p() where the $mode of the parent folder is not correctly applied to all created paths. Merges [26449] and [26927] from 3.8.x to the 3.7 branch. props dd32. fixes #25822. git-svn-id: https://develop.svn.wordpress.org/branches/3.7@27887 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index aea813b7d0..c9db091009 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -1372,14 +1372,23 @@ function wp_mkdir_p( $target ) { } // Get the permission bits. - if ( $target_parent && '.' != $target_parent ) { - $stat = @stat( $target_parent ); + $dir_perms = false; + if ( $stat = @stat( $target_parent ) ) { $dir_perms = $stat['mode'] & 0007777; } else { $dir_perms = 0777; } if ( @mkdir( $target, $dir_perms, true ) ) { + + // If a umask is set that modifies $dir_perms, we'll have to re-set the $dir_perms correctly with chmod() + if ( $dir_perms != ( $dir_perms & ~umask() ) ) { + $folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) ); + for ( $i = 1; $i <= count( $folder_parts ); $i++ ) { + @chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms ); + } + } + return true; }