Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. $environments = array(
  2.   'local-mamp' => 'localhost',
  3.   'local-codekit' => '5757',
  4.   'staging' => 'clients.monderer.com',
  5.   'production' => 'inno4llc.com',
  6. );
  7.  
  8. // Get the hostname
  9. $http_host = $_SERVER['HTTP_HOST'];
  10.  
  11. foreach($environments as $environment => $hostname) {
  12.   if (stristr($http_host, $hostname) !== FALSE) {
  13.     define('ENVIRONMENT', $environment);
  14.     break;
  15.   }
  16. }
  17.  
  18. // Exit if ENVIRONMENT is undefined
  19. if (!defined('ENVIRONMENT')) exit('No defined database configured for this host' . $http_host);
  20.  
  21. // Location of environment-specific configuration
  22. $wp_db_config = 'wp-config/wp-db-' . ENVIRONMENT . '.php';
  23.  
  24. // Check to see if the configuration file for the environment exists
  25. if (file_exists(__DIR__ . '/' . $wp_db_config)) {
  26.   require_once($wp_db_config);
  27. } else {
  28.   // Exit if configuration file does not exist
  29.   exit('No database configuration file found for this host');
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement