<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>odyniec.net blog &#187; WordPress</title>
	<atom:link href="http://odyniec.net/blog/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://odyniec.net/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 28 Aug 2010 23:15:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress Blog and Multiple Server Names</title>
		<link>http://odyniec.net/blog/2010/02/wordpress-blog-and-multiple-server-names/</link>
		<comments>http://odyniec.net/blog/2010/02/wordpress-blog-and-multiple-server-names/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 22:24:11 +0000</pubDate>
		<dc:creator>Michal Wojciechowski</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://odyniec.net/blog/?p=430</guid>
		<description><![CDATA[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&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently updating my <a href="http://wordpress.org/">WordPress</a> 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.</p>
<p>Unfortunately, WordPress didn&#8217;t get along with this solution especially well. The WordPress engine didn&#8217;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&#8217;t log in to the administrative interface at the test version, as it kept redirecting me to the live login page.</p>
<p>I knew PHP stored the actual host name that was used to access the page in the <a href="http://www.php.net/manual/en/reserved.variables.server.php">$_SERVER['SERVER_NAME']</a> 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&#8217;t affect the base WordPress code.</p>
<p>So, behold! My first WordPress plugin ever:</p>
<p><p class="code">&lt;?php

/*
Plugin Name:    Server Name Support
Description:    Allows the blog to be accessed with multiple 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');

?&gt;</p></p>
<p>In case you&#8217;d like to use it (not very likely, as I don&#8217;t think my use case is that common), all you need to do is save the above code in a <code>.php</code> file, place it in the <code>wp-content/plugins</code> directory, and activate it in the WordPress admin interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://odyniec.net/blog/2010/02/wordpress-blog-and-multiple-server-names/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
