On June 8, 2013 I gave a talk about automating your WordPress development Workflow at WordCamp Milwaukee. Here are the slides along with some notes.

As I’ve mentioned before, computers are really good at carrying out repetitive tasks and we should use that to our advantage to make development easier.

We all know you should develop locally and on the latest development version of WordPress. But in order to checkout the trunk, you have to use SVN β€” unless you know about git-svn. You can checkout the entire core repository with:

git svn clone -s http://core.svn.wordpress.org

That’s going to take a while because it is going to download all the WordPress history from forever, but once it’s done it’s just another simple git-svn command to keep it up to date:

git svn rebase

You can also put git repositories inside other git repositories. This is useful so you can use a different repository for each plugin and theme. Just initialize a new repository in the themes or plugins directory and it will work just like normal β€” even if you’re already using git to manage your development version of WordPress.

Automate your Environment

If you like using a virtual machine for your local development environment, vagrant has to be the way to go. A simple configuration file defines the virtual machine and vagrant, which relies on VirtualBox, takes care of setting it up. Pair that with provisioning software like Puppet or Chef and you’ve got a development environment that you can get up and running with a single command.

Vagrant depends on a Vagrantfile that defines the virtual machine. It’s important to note that the folder that the Vagrantfile lives in will be shared using VirtualBox’s built in sharing on the guest to /vagrant.

Puppet scripts define how a server should look. So, “has apache, php, and mysql installed” is an example. The idempotence of puppet is really cool. You can run a puppet script over and over again and it won’t break anything. If you say a server should have nginx and it already has nginx, puppet will just skip that step. The weird part about puppet, and the thing I found most confusing at first, was that stuff doesn’t run in order. You have to clearly specify dependences because the software is going to optimize your script as much as possible. This gets easier to follow once you work with it for a while.

My current setup is at https://github.com/joshbetz/WCMKE–2013-Vagrant-Puppet

When everything is configured, simply run vagrant up and vagrant will start the virtual machine. Other commands are vagrant ssh, vagrant halt, vagrant destroy, and vagrant provision. SSH is straight forward. Halt shuts down the machine. Destroy removes the machine from VirtualBox. Provision runs the provisioner, whether that’s Puppet, Chef, or a shell script.

This is really powerful. Like your dotfiles, you can put this in the cloud and download the configuration when you need it. And simply run vagrant up to start the machine.

The other nice thing is that our development environments can be open source now. Working together on this stuff is a powerful thing, but I don’t think I have to convince the WordPress community of the power of open source.

Automate your Development

Since we are talking about WordPress development, I’m also going to mention some ways you can make the software work for you while you’re writing code.

  1. Developer Plugin – http://wordpress.org/extend/plugins/developer/
    It’s maintained by Automattic and basically just helps you set up your local development environment the right way. From checking your wp-config.php for the proper constants, to verifying that you’re on the latest development release of WordPress, to recommending awesome plugins that make WordPress development run more smoothly.

  2. Theme Unit Test – http://codex.wordpress.org/Theme_Unit_Test
    This one is maintained by the WordPress Theme Review Team. Even though it’s called the Theme Unit Test, this is useful for all developers. It’s a collection of a huge range of content for you to import into WordPress. Even if you’re developing the next hit plugin, you’re going to need content to test on. There are posts of every post format and any kind of example you could think of.

  3. Underscores.me – http://underscores.me
    Something else that is maintained by Automattic. While it’s technically a theme, I think of it more as a collection of awesome snippets that you can drop into your theme. That’s not to say you couldn’t download this and style it the way you want and be done. It would probably be great as a theme by itself, but there’s so much awesome in here that I just like to scan through the code once in a while and see what new magic I find.

So, to wrap this up, make your computer work for you. Automate everything that can be automated unless you know you’ll never need to do it again. When you do something twice, that’s a good sign that you’ll probably do it again. πŸ™‚