I don’t think I ever had practical need to create folders/files in WP before, but for a plugin I need cache (for resized images) folder in wp-content/uploads
.
Which raises the question – do I really need to go through all the process with Filesystem API
(including messily asking for FTP credentials when needed), or wp_mkdir_p()
is good enough for this?
wp-content/uploads/
should be writable for the server (otherwise it would be impossible to upload a file, no?). If you are going to create something under this directory, it is safe to usewp_mkdir_p()
.I would only use
WP_Filesystem
if there is a chance the server does not have permissions to write to the location, like inwp-content/plugins/
, which does not have to be writable for the server (at least I think it doesn’t have to be?).Sidenote: The File Permissions page of the Codex also talks about a
wp-content/cache/
directory. Would this be a “more standard” location for cache files?I’d try something simple, before messing around with an endless sea of possibilites/hosting setups:
Just a heads up on having your plugin create files/folders: my plugin did that as well, and I ran into a slew of issues with file permissions for different users. Some are windows, some are unix, some are hosted, and some home grown. It was my #1 support email once I shared the plugin.
I have refactored my code to minimize the need to touch the file systems and the upload directory is the ONLY one I use now to avoid such issues.