Last active
August 29, 2015 14:04
-
-
Save jloescher/ad9e937747cf76ab5751 to your computer and use it in GitHub Desktop.
Multi Environments | WP-Config.php
This file contains hidden or 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
<?php | |
/** Absolute path to the WordPress directory. **/ | |
if ( !defined('ABSPATH') ) | |
define('ABSPATH', dirname(__FILE__) . '/'); | |
/** Define Environments **/ | |
$environments = array( | |
'localhost' => 'localhost', | |
'development' => '', | |
'staging' => '', | |
'production' => '' | |
); | |
/** Get Server name **/ | |
$server_name = $_SERVER['SERVER_NAME']; | |
/** Detect Environment **/ | |
foreach($environments AS $key => $host){ | |
if ($server_name === $host) { | |
define('ENVIRONMENT', $key); | |
break; | |
} | |
} | |
/** Failsafe if no environment defined **/ | |
if (!defined('ENVIRONMENT')) { | |
echo '<h2>The detected host has not been defined, please define in the "Define Environments" section of the wp-config.php file.</h2>'; | |
echo '<br />'; | |
echo '<h3>Detected Host: ' . $server_name . '</h3>'; | |
echo '<hr />'; | |
} else { | |
/** Load configuration based on the server's environment if environment is defined **/ | |
require_once ABSPATH . 'wp-config/wp-config.' . strtolower(ENVIRONMENT) . '.php'; | |
} | |
/** Sets up WordPress vars and included files. */ | |
require_once(ABSPATH . 'wp-settings.php'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment