wp-mconfig

Problem: We develop multiple wordpress sites for people and need a way to easily switch from one client to another without having 30 installs of wordpress lying around.

Solution: Create a directory wp-config in your wordpress home directory and load it with copies of your config files but with a .cfg extension. This is neither elegant nor clean but it works great in a simple development system.

Create a file in your wordpress home directory called wp-localize.php and paste in the following code:

if (isset($_GET['file'])) {
$cfg = $_GET['file'];

copy(‘./wp-config/’ . $cfg, ‘./wp-config.php’);

include_once(“wp-config.php”);

$v = “http://” . $_SERVER['SERVER_ADDR'] . “/wordpress/”;

$v = ” update $wpdb->options
set option_value = ‘$v’
where option_name = ‘siteurl’ or option_name = ‘home’”;

//echo “[" . __FILE__ . ":" . __LINE__ . "] Setting Site URL<br>
// SQL => <br>\n<blockquote>$v</blockquote>”;

// – ONLY USE IF NECESSARY! We have multiple servers to contend with.: $wpdb->query($v);
}

if ($handle = opendir(‘./wp-config/’)) {

while (false !== ($file = readdir($handle))) {
if (! strpos($file, “.cfg”) === FALSE ) {
echo “<p><a href=\”wp-localize.php?file=$file\”>$file</a></p>”;

}

}
closedir($handle);
}

Leave a Reply

You must be logged in to post a comment.