Load different config files in in WordPress single implementation

Description:

Having multiple databases on the same implementation of WordPress, you need to select the proper config file before running a selected script from command line

Solution:

Just add a parameter that describes the correct config you need, for example a country parameter, in the script, before loading the config:

//return proper config file
if ( !defined(‘ABSPATH’) )
define(‘ABSPATH’, dirname(__FILE__) . ‘/’);

$differentParameter = ”;
if (isset($argv[1]) && is_string($argv[1])) {
$country = $argv[1];
$configFile = ABSPATH . ‘wp-config-‘ . $differentParameter . ‘.php’;
if ( file_exists($configFile)) {
require_once($configFile);
}
} else {
require_once(‘wp-config.php’);
}

Advertisements

About admin

Just another php developer trying to give something back to the community.
This entry was posted in Best practices, Script, Wordpress and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s