Last active
December 14, 2015 12:18
-
-
Save burbridgeconsulting/5084938 to your computer and use it in GitHub Desktop.
WordPress config environment conditionals. See comments for instructions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ** Define environments for different machines. | |
$user = $_ENV['LOGNAME']; | |
$host = $_SERVER['HTTP_HOST']; | |
$environment = $user . ' / ' . $host; | |
switch ($environment) { | |
case 'chrisburbridge / mysite.dev': | |
define('DB_NAME', 'xxxxxxxxx'); | |
define('DB_USER', 'aaaaaaa'); | |
define('DB_PASSWORD', 'mmmmmmmm'); | |
define('DB_HOST', 'localhost'); | |
define('SITE_DEV', 'true'); | |
break; | |
case ' / dev.mysite.com': | |
define('DB_NAME', 'yyyyyyyy'); | |
define('DB_USER', 'bbbbbbb'); | |
define('DB_PASSWORD', 'zzzzzzzz'); | |
define('DB_HOST', 'localhost'); | |
break; | |
default: | |
define('DB_NAME', 'zzzzzzzzz'); | |
define('DB_USER', 'cccccccc'); | |
define('DB_PASSWORD', 'nnnnnnnnn'); | |
define('DB_HOST', 'localhost'); | |
break; | |
} |
Is it possible to write a define statement that only applies to one website in a multisite environment?
Basically like conditional instructions per website...
e.g. All of website allows for define ( revisions 3 ); but I wan't one of the website's in the multisite environment to have define ( revisions 10 ); that is setup for training.
Any help would be appreciated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place this at the top of your wp-config.php file. If you are maintaining source at the Document Root level, this will let you handle the variations between development, local, production, etc., environments.
$user and $host will change for your uses. You can use this line to see what it is on a given machine, which you will only have to do once:
echo "\$environment='{$environment}'";
Once you have this set up, not only can you maintain the same source tree for different machines (including collaborators), note how I have defined SITE_DEV as a constant for my development environment. This means I can also do things like turn on debugging features throughout the code, that only show if SITE_DEV is active for that environment.