Testing on Mulitple Versions

Posted: 9th Feb 2008, in: Snippets, Themery, plugins - Older Post - Newer Post

I’ve had a dilemma for a little while. I’m developing a theme that I wanted to test on multiple local versions of WordPress, but copying it between directories seemed to be a bit painful, as does stopping and starting Apache each time I want to re-test. I have finally found a pretty workable solution: Use the same themes folder for every installation of WordPress. Here’s how I’ve done it.

Note: If you haven’t already installed a local version of WordPress this post possibly isn’t for you. I suggest reading these first: Installing WordPress Locally Part 1 - Installing WordPress Locally Part 2

Two Instances of Apache

First I have created a folder for each WordPress installation, unzipped the versions (in my case 2.3.2 and 2.5), created a separate database schema for each in Mysql and completed the WordPress config files to point the right schema.

Second, I have created multiple Apache config files and shortcuts. The config file (on Windows at least) by default is called httpd.conf. The lines that differ in each config file are:

...
Listen 8080 (Change the port to anything different)
...
ServerName locahost:8080 (the port number should match the first change above)
...
DocumentRoot "C:\wordpress" (point to the folder where the installation can be found)
...

To create a new shortcut (again Windows only. If a Mac / Linux fan can give some advice in the comments it would be much appreciated) find the shortcut file, there is often one in the start menu, under Apache, labelled ‘Start Apache in Console’ and copy it. Right click on it and select properties. The target field will have the path to the original conf file in it, it will be something like:

…”C:\Program Files\Apache Group\Apache2\conf\httpd.conf”…

Change only this part of the target, there will be other paths in there but only this one should be changed to point to your new conf file.

You should now be able to run two, or more, instances of Apache side by side by using these shortcuts.

Redirect WordPress to one Themes Folder

Once you have all the versions of WordPress up and running you will need a very simple plugin to tell WordPress to look in a different folder for themes:

add_filter(‘theme_root’ , ‘theme_root_intercept’);
 
function theme_root_intercept($root){
	return "C:\favewordpressinst/wp-content/themes";
}

This intercepts the request for the theme folder and gives it the one you want it to use. Just change the path to suit you.

Redirect the Browser

Finally, we need to redirect any browser requests by adding the following line (suitably amended ) to you .htaccess file:

RewriteRule ^wp-content/themes/(.*)$ http://localhost:8080/wp-content/themes/$1 [L]

If you are using permalinks this will need to be above the rewrite conditions.

What about plugins?

There doesn’t seem to be similar filter for plugins so it is does involve making a minor edit to a core file.

WordPress uses two constants to find the plugin path, ABSPATH which you can’t really mess with, and PLUGINDIR which you can. You can change it in wp-settings.php which is in the main folder. Because it will have the current ABSPATH added on front you will need to make this come back up enough directories to find the one you need; for example:

define(‘PLUGINDIR’, ‘../wordpress-svn/wp-content/plugins’);

You will also need a similar .htaccess directive, but relating to the plugins directory instead.

I haven’t had much time to test this yet so treat it with caution and don’t link to any data you want to keep.

 

Comments

  1. 1

    ThaNerd (http://www.thanerd.net/) commented at 10:17 pm, 19th 02 2008:

    On any LAMP (Linux+Apache+MySql+PHP), you’d just have created a symbolic link… Say you have two websites with Document root respectively /var/www/first and /var/www/second, and a “base” dir with all plugins in /var/www/base/wp-content/…

    You’d do this:
    cd /var/www/first/wp-content
    rm -r plugins themes
    ln -s plugins /var/www/base/wp-content/plugins/
    ln -s themes /var/www/base/wp-content/themes/
    cd ../../second/wp-content/
    rm -r plugins themes
    ln -s plugins /var/www/base/wp-content/plugins/
    ln -s themes /var/www/base/wp-content/themes/

    I didn’t use Windows in a while, but i *know* that NTFS filesystems can handle so-called “symbolic links”, but the feature is not extensively documented, and there is no tool to create them in a default windows setup. However, a compagny named “Sysinternals” had created such a tool and distributed it as a freeware. Meanwhile, SysInternals has been bought by Microsoft, but a few months ago, i know one could still download those tools from microsoft website for free.

    Just Google it :D

     
  2. 2

    Andrew Rickmann (http://www.arickmann.co.uk) commented at 10:55 pm, 19th 02 2008:

    Thanks, that’s great info.

    I’ve found the following on the Microsoft site which seems to be what you were referring to.

    http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx

     
  3. 3

    Vix (http://garinungkadol.com) commented at 10:35 am, 27th 02 2008:

    I had never considered sharing my wp-content folder across multiple installations. Thanks for the tip!

    In addition to filtering out the theme_root, I also had to filter the theme_root_uri using:
    add_filter('theme_root_uri', 'theme_root_uri_intercept');
    function theme_root_uri_intercept($root) {
    return "http://localhost/wordpress-files/wp-content/themes";
    }

     
  4. 4

    Andrew Rickmann (http://www.arickmann.co.uk) commented at 12:20 pm, 27th 02 2008:

    Thanks Vix,

    I never thought to change the URI in the plugin, probably because I was using some manually included absolute uris in the theme I was testing, so that is why I used the .htaccess rule.

    In most cases though your code should do the trick and it means there is only one thing to change to put it back again.

     

Other blogs writing about this

  1. WordPress Weekly Episode 6 » Jeffro2pt0 (http://www.jeffro2pt0.com/wordpress-weekly-episode-6/) 16th 02 2008 at 7:05 am

    [...] http://www.wp-fun.co.uk/2008/02/09/testing-on-mulitple-versions/ [...]

     
  2. WordPress Weekly Episode 6 | Jeffro2pt0 (http://www.jeffro2pt0.com/wordpress-weekly-episode-6) 25th 04 2008 at 8:58 am

    [...] http://www.wp-fun.co.uk/2008/02/09/testing-on-mulitple-versions/ [...]

     

Leave a Reply

I am currently testing a comment link policy which means commenters do not get a link. There is a poll, and open comments for feedback on the comment policy page.

Please note. I am currently using an experimental antispam technique on this blog. If you run into problems please let me know using the Get in Touch link at the top of the page. Thanks, Andy.

Subscribe without commenting

Feed Icon - Get fed with RSS