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
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 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.
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.phpfor 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.
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.
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.
Since I recently switched from VIM back to Sublime Text 3, I thought I’d share some of the packages that I’m using.
While Sublime Text 3 is still in beta, it seems to be stable enough to use. That being said, many of the packages have limited or no support for Python 3 at this point, which is necessary for ST3. Some of the more popular packages have branches on GitHub dedicated to Sublime Text 3 support. You can install those packages through Package Control by first adding the URL associated with that branch as a repository. For example, “https://github.com/weslly/Nettuts-Fetch/tree/st3”.
First, since I came from VIM, I thought it would be nice to use Vintage. I’ve used Vintage in the past and haven’t necessarily loved it though. Luckily, while I was searching for other packages that have Sublime Text 3 support, I stumbled upon Vintageous which has been excellent so far. At this point it’s kind of the reason that I don’t want to go back to Sublime Text 2.
I was very happy to find that Package Control works in ST3. There are special installation instructions that involve manually cloning the repository, but nothing too complicated. After the initial install process, everything seems to work like normal.
Since the theme and color definitions aren’t dependent on a particular version of Python, the old themes and color schemes should still work. As always, I’m using the Soda theme with the Tomorrow Night color scheme. For now, I’m using the Tomorrow Night Eighties variant because it’s so hipster.
Like the themes, language definitions aren’t dependent on a particular version of Python. The additional language definitions I’ve installed are CoffeeScript and Sass.
Lastly, I’m using a few other utility packages that just make life easier.
- GitGutter: I used something similar to this in VIM and I couldn’t imagine life without it. Basically, it tells you what changes have been made to the current file since the last commit.
- Alignment: The standard version of this one doesn’t work, so you’ll have to find a working fork. I’m using https://github.com/kevinsperrine/sublime_alignment/tree/python3 and it works so far. This one lines up stuff in your code. I primarily use it on long lists of variable definitions or similar blocks so that all the equals symbols line up, making the code easier to read.
- Fetch: Another package that needs the correct branch to be manually added to package control at this point. https://github.com/weslly/Nettuts-Fetch/tree/st3 is what I’m using. Since it’s made by Nettuts, I’ll let them explain in their article, Introducing Nettuts+ Fetch.
- SublimeLinter: While SublimeLinter theoretically works with ST3, I haven’t been able to use it so far. Even though I normally don’t have an issue missing semicolons and such, it’s nice to have a linter watching your code so you don’t waste time tracking down bugs based on syntax errors.
I’ll be at WordCamp Milwaukee this year talking about some of the things I do to ease the process of developing WordPress plugins and themes. Computers are really good at following instructions and carrying out repetitive tasks, so we should use that to our advantage and automate away the “setup”, which will allow us to focus on the task at hand — creating the next hit plugin or theme.
I’ve been to WordCamps in the past and it’s always a good chance to meet other people who use and develop for WordPress on a daily basis. So whether you’re a developer that’s been using it for years or someone who is just thinking about starting your first WordPress blog, WordCamp Milwaukee will have something for everyone. As you may know, the WordPress community is filled with people that want to help and this is your opportunity to talk to them face to face.
If you decide to go, you can use the coupon code “betz” to save $5 at checkout.
git-bisect – Binary search the history to find a bug.
Not me, I still use a combination of Safari and Chrome Canary.
Firefox greets me with a page explaining my rights as a user of open source software. Chrome greets me with… sigh… Chrome greets me with a fucking advertisement for a Chromebook.
It’s an interesting article though.