Using symlinks to aid wordpress plugin development
This is a quick post to explain how I arrange my development environment and use symlinks to aid wordpress plugin development. Although it isn’t essential, I find it helps me to keep the different projects I’m working on in separate directories from the rest of the wordpress install.
In my setup, I have all my sites set up in a directory structure in /usr/local/sites and then I create directories for the plugins I’m working on in /usr/local/localdev
As an example, let’s supposeĀ I’m working on a plugin called ‘coolplugin’ and I’ve set up a wordpress site called coolsite.co.uk which will be the test domain for it. Following my normal file system setup, the site would be created in /usr/local/sites/coolsite.co.uk/wordpress and the plugin would be created inĀ /usr/local/localdev/coolplugin
In order to make the plugin visible in the wordpress site, I would set up a link like this:
sudo ln -s /usr/local/localdev/coolplugin /usr/local/sites/coolsite.co.uk/wordpress/wp-content/plugins/coolplugin
This will create a directory in the plugins directory of coolsite.co.uk which links to the plugin development code. The link is set as a softlink, which means it points to the name of the destination folder; if you change the name of your development folder the link will break so you need to be aware of that.
In order to allow both me as a developer to change the code, and the webserver to run the code, I set the permissions so that I am the owner of the files and the group is www-data. This is achieved with
cd /usr/local/localdev
sudo chown simon:www-data coolplugin -R
With this set up, if you go to the plugins page of the test site you should find that the plugin is listed and can be enabled and used. As you make changes to the code in the plugin directory it will immediately be available on the site so you can work in exactly the same way as if the code was installed in the plugins directory.
Why go to this trouble you may ask?
Well, I guess it’s a personal preference, but I find it easier to set up a project in my IDE (PhpStorm) which just contains the code to the plugin I’m working on and I like the code to be completely separate from the wordpress install and using symlinks allows that.