Archive for February, 2010

WordPress Blog and Multiple Server Names

Friday, February 26th, 2010

I was recently updating my WordPress installation to a freshly released version. My traditional procedure of updating the website is to first make changes to a test version (which is set up on a subdomain of odyniec.net), make sure everything works and looks right, then copy the test files to the public location.

Unfortunately, WordPress didn’t get along with this solution especially well. The WordPress engine didn’t like being accessed through the test subdomain, as it expected a single host name to be designated as its home location. Even though I could open the blog at the test address, all the dynamically generated links to scripts, style sheets, archives and such still pointed to the live version. I also couldn’t log in to the administrative interface at the test version, as it kept redirecting me to the live login page.

I knew PHP stored the actual host name that was used to access the page in the $_SERVER['SERVER_NAME'] variable, and I thought a simple solution would be to make WordPress use that instead of the basic URL set in the configuration. I had very little experience with WordPress internals, so it took me some time to figure out how to implement this, but I eventually succeeded. I wrapped the code into a plugin so that the functionality can be easily enabled or disabled and doesn’t affect the base WordPress code.

So, behold! My first WordPress plugin ever:

<?php

/*
Plugin Name:    Server Name Support
Description:    Allows the blog to be accessed with different server names
Author:         Michal Wojciechowski
Version:        0.0.1
Author URI:     http://odyniec.net/
*/

$sns_home = preg_replace('!://[a-z0-9.-]*!', '://' . $_SERVER['SERVER_NAME'],
    get_option('home'));

function sns_home()
{
    global $sns_home;

    return $sns_home;
}

function sns_replace_host($url, $path = '')
{
    return preg_replace('!://[a-z0-9.-]*!', '://' . $_SERVER['SERVER_NAME'],
        $url);
}

add_filter('pre_option_home', 'sns_home');
add_filter('pre_option_siteurl', 'sns_home');
add_filter('pre_option_url', 'sns_home');
add_filter('stylesheet_uri', 'sns_replace_host');

add_filter('admin_url', 'sns_replace_host');

?>

In case you’d like to use it (not very likely, as I don’t think my use case is that common), all you need to do is save the above code in a .php file, place it in the wp-content/plugins directory, and activate it in the WordPress admin interface.

ImgAreaSelect 0.9.2

Saturday, February 20th, 2010

ImgAreaSelect version 0.9.2 is out. This version fixes a few minor bugs, and introduces a new option that allows you to completely remove the plugin from the image that it was attached to. Thanks to all the people who helped me by reporting bugs and sending feedback.

I have also added a new example to the Advanced Usage page — it demonstrates an extension of the plugin API that allows you to animate the selection area.

Running Multiple Versions of Firefox in Ubuntu 9.10

Tuesday, February 9th, 2010

Here’s a simple howto on running several different versions of Firefox in Ubuntu 9.10. This is the setup that I use to test my jQuery plugins and other JavaScript code — I hope some of you fellow developers out there will find it useful too. The basic advantage of this solution is that is does not clutter your basic system with unnecessary software packages, as all the additional files are stored in your home directory and nowhere else.

I’m going to create a directory where all the different Firefox versions will reside. I have a dedicated directory for any software that I can’t or don’t want to install the standard way (using apt), and it is located in my home directory – /home/michal/opt. It serves a similar purpose as the system-wide opt directory, which is intended for “optional” software.

$ mkdir /home/michal/opt/firefoxes

There it is. Now, I’m going to get all those versions of Firefox that I want to run. As of this writing, the version running in my system is 3.5.7. I decided to also install the latest version of the 3.0 series (3.0.17), the prehistoric 2.0.0.20 release, as well as the freshly released Firefox 3.6.

Actually, according to browser usage statistics (such as those run by Clicky and StatCounter), Firefox 2.0 has a market share below one percent, so it’s questionable whether web developers should still care about it. I just happen to like to see if new versions of my jQuery plugins still work in the older browsers, so I’m going to install it.

Binary packages for all Firefox releases can be downloaded from the Mozilla FTP server at ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/. Here are the respective URLs for the versions that I’ve chosen:

So now I’ll go to the firefoxes directory and download the three packages with wget (of course, you can also download them using your browser or any FTP client):

$ cd /home/michal/opt/firefoxes $ wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/2.0.0.20/linux-i686/en-US/firefox-2.0.0.20.tar.gz $ wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.0.17/linux-i686/en-US/firefox-3.0.17.tar.bz2 $ wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.6/linux-i686/en-US/firefox-3.6.tar.bz2

(more…)