January 1, 2011

WordPress and Subversion

If there’s two bits of software I love, WordPress and Subversion would be right up there in terms of making my life simpler, and making publishing easier. While it’s tempting to counter statements like these with a long list of problems, I’ll leave that as it is – today I want to convey a few things that helped me use the two pieces of software together.

First, the context of using WordPress and Subversion jointly is typically in making sure that customer websites are fully versioned so that we can be accountable and transparent, and equally importantly so that we can roll back in a disaster scenario.

Second, some background on our approach. We believe that when using Open Source software for customers, it’s important to strike a balance between cutting edge features and stability. We typically accomplish this by starting the project at the head revision of the software we’re using – in this case, WordPress.

1

Now we have a freshly checked out copy of WordPress, and we’ll want to keep it this way. If you don’t feel comfortable with leaving a repository in a certain state there are a few options here – the most obvious would be for you to maintain your own copy of the WordPress source tree (which can be useful in other ways too, for instance if WP’s subversion servers were to go down.) This can be accomplished easily using `svnsync`.

Assuming that you’re happy with your checked-out WordPress, we now want to move all the User data to one place, so that we can version it separately to the WordPress trunk. Typically, this is just the `wp-content` folder, but you may also want to version wp-config.php, .htaccess, and any other special files you’re using in the project webroot.

Your final decision on the path structure really depends on the scenario- you may want to separate out the theme directory from other ‘user content’ directories if you’re planning to open source your theme or host it elsewhere. In this case, you’d have a subversion repository containing the folders within wp-content, with a `themes` folder which will load your versioned theme(s) as an svn:externals entry.

Now, a couple of tricks – first, your uploads folder may want to be versioned. If not, you’ll want to svn:ignore it. If you do version it, you’ll probably want to svn:ignore some of it. For instance, WP2.5 onwards supports image resizing, and it uses the uploads directory also as a cache store for these thumbnails. We can ignore these thumbnails by setting the svn:ignore property on the uploads directory as follows:

1

Note that if your uploads folder is structured by date, these ignore settings will not persist in new directories, so I’d recommend you do not use a structured uploads folder if you are versioning it (the option titled ” Organize my uploads into month- and year-based folders”).