[wp-hackers] Where Should Plugins Store Files?

Dougal Campbell dougal at gunters.org
Mon Sep 13 12:59:05 UTC 2010


  On Sep 13 2010 7:12 AM, Ryan McCue wrote:
>   Andrew Nacin wrote:
>> That's a bad idea. Then you lose that file on an upgrade.
>>
>> You can use wp_mkdir_p($path) to create a folder. (The _p means it attempts
>> to set permissions.) If fails, it will return a WP_Error object.
> What's the opinion on creating new subdirectories of wp-content, as
> opposed to being in existing directories (i.e.
> wp-content/plugin/file.html vs. wp-content/uploads/plugin/file.html)?
> I'm currently using the former for a couple of configuration options
> (overriding a template that the plugin uses, but optional), but the user
> creates the directory and file themselves.
>
> Are there any forseen problems to this sort of setup?
>

I've always thought that 'wp-content/[myplugin]/' should be the standard 
for plugins to store persistent files. But you can't always depend on it 
to be writable, so you'd want to fall back to the uploads dir (and of 
course, handle errors when that's not available either). I'd check which 
directory was available at plugin activation time, and store the result 
in an option, so that you stay consistent once you've started using one 
location or another.


-- 
Dougal Campbell <dougal at gunters.org>
http://dougal.gunters.org/
http://twitter.com/dougal
http://twitual.com/


More information about the wp-hackers mailing list