$file_dir = WP_CONTENT_DIR . '/uploads/foo/';
Why would you need to use wp_mkdir_p when mkdir can do its job here?
if(!file_exists($file_dir))wp_mkdir_p($file_dir);
or
if(!file_exists($file_dir))mkdir($file_dir);
$file_dir = WP_CONTENT_DIR . '/uploads/foo/';
Why would you need to use wp_mkdir_p when mkdir can do its job here?
if(!file_exists($file_dir))wp_mkdir_p($file_dir);
or
if(!file_exists($file_dir))mkdir($file_dir);
Share
Improve this question
asked Apr 30, 2017 at 21:18
ToniqToniq
4476 silver badges15 bronze badges
1
|
1 Answer
Reset to default 5There is not much a difference but, for wp_mkdir_p()
we can only pass the full path to attempt to create a folder. It is recursive directory creation function which check for the file_exists()
or not. And moreover we don't need to pass the folder permission because it checks for the parent directory permission and sets the folder permission as that of the parent directory.
But, with mkdir()
we need to check for the file_exists()
function before creating a directory and the directory permission will be set as the permission defined by the WordPress itself during the setup.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745111245a4611865.html
wp_mkdir_p
in source to see what it does. – Milo Commented Apr 30, 2017 at 22:12