The thoughts, opinions and sometimes the rants of Mark Evans

Stop Writing to Yourself

| Comments

One of the frustrations I’ve come across recently when trying to deploy Wordpress in an enterprise environment is plugins which attempt to write content or debugging to the same folder they sit in, namely the “plugins” folder.

As part of my requirements to make Wordpress easily deployable I wanted to make sure that the wp-content folder sat on a networked file system as I needed to deploy a site to run across multiple webservers, I also didn’t want to have to deal with messy symlinks everywhere so I thought moving the plugins dir outside of wp-content would be simple.

To do this I just added a couple of simple defines to my wp-config.php file

define('WP_PLUGIN_DIR', dirname( __FILE__ ) . '/plugins' );
define('WP_PLUGIN_URL', '');

I thought, wow that was so easy how come I kept hearing all of these complaints about Wordpress, deploying it was simple. Then BAM I came across a number of plugins which attempt to write to WP_PLUGIN_DIR. It was at this point in my head I shouted WTF!!! at the top of my voice, why on earth would plugins want to write to themselves, surely that is the whole point of wp-content?

The first of these I came across was Simple Ads Manager

Open up sam.class.php and you will be greeted with the following

define('SAM_AD_IMG', WP_PLUGIN_DIR.'/sam-images/');
define('SAM_AD_URL', plugins_url('/sam-images/'));

Lovely, so you have a plugin which allows you to upload images to use in ad placements but these are being saved to the plugins folder rather that the content folder. This totally screws up my plans to separate content from plugins.

I spent a small amount of time Googling around for best practices for Wordpress plugins and quite surprisingly I didn’t find any advice about writing content to WP_CONTENT_DIR vs WP_PLUGIN_DIR, when talking to other Wordpress developers it seems that they just accept that plugins do that.

I’m planning on offering a patch to the author of Simple Ad Manager to see if we can find a solution which doesn’t break backwards compatibility but will mean that I don’t need to maintain my own version of the module as I am sure that it should be using WP_CONTENT_DIR for its uploads, fingers crossed the plugin author agrees.

I am sure there are lots more plugins out there which do strange things, I just hope I don’t need to use too many of them.

If anyone feels that writing to WP_PLUGIN_DIR is actually valid, please let me know as I’d love to find out what scenario’s people think the different folders should be used for, you might even get me to change my mind.