If you are developing wordpress sites then more than likely you will be setting up a local dev version using something like MAMP PRO and then staging the development on your live production server at your web host.
By far the most easiest way I have found to accomplish auto switching between dev connection and live connection is to do the following.
- make two copies of your wp-config.php
- rename one of them wp-config-live.php
- rename the other file wp-config-dev.php
- open the original wp-config.php file and delete everything and drop in the following code
All you have to do then is edit the dev server name in wp-config.php, then just update the test and live config files and you are done.
Job Done! Now you have two separate config files for each server you are running.
{code type=php}
//this file has been created so that we can use the same files on a local test server and live server
//craigedmonds.com 23/4/2012
//define your url for your test server
$dev_server = 'localhost.yourdomain.com';
//get relevant config file based on the host
if ( $_SERVER['HTTP_HOST'] == $dev_server ) {
include "wp-config-dev.php";
} else {
include "wp-config-live.php";
}
?>
{/code}