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’);
}

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 comment