Skip to content

Instantly share code, notes, and snippets.

@gisu
Last active December 20, 2015 12:00
Show Gist options
  • Save gisu/e856f71929c0a00c51af to your computer and use it in GitHub Desktop.
Save gisu/e856f71929c0a00c51af to your computer and use it in GitHub Desktop.
Multienvironment Worpdress
Include a directory in your Theme folder with the name `wp-config` and include here the File for your Environment.
<?php
/**
* @package WordPress
*/
// Set your environment/url pairs
$environments = array(
'dev' => 'dev.local',
'stage' => 'stage.site.com',
'production' => 'site.com'
);
// Get the hostname
$http_host = $_SERVER['HTTP_HOST'];
// Loop through $environments to see if there’s a match
foreach($environments as $environment => $hostname) {
if (stripos($http_host, $hostname) !== FALSE) {
define('ENVIRONMENT', $environment);
break;
}
}
// Exit if ENVIRONMENT is undefined
if (!defined('ENVIRONMENT')) exit('No database configured for this host');
// Location of environment-specific configuration
$wp_db_config = 'wp-config/wp-db-' . ENVIRONMENT . '.php';
// Check to see if the configuration file for the environment exists
if (file_exists(__DIR__ . '/' . $wp_db_config)) {
require_once($wp_db_config);
} else {
// Exit if configuration file does not exist
exit('No database configuration found for this host');
}
// Global DB Config
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
/**#@+
*
*/
define('AUTH_KEY', '...');
define('SECURE_AUTH_KEY', '...');
define('LOGGED_IN_KEY', '...');
define('NONCE_KEY', '...');
define('AUTH_SALT', '...');
define('SECURE_AUTH_SALT', '...');
define('LOGGED_IN_SALT', '...');
define('NONCE_SALT', '...');
/**#@-*/
$table_prefix = 'wp';
define('WPLANG', 'de_DE');
define('DISALLOW_FILE_EDIT', true);
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
<?php
// Prevent file from being accessed directly
if (!defined('ABSPATH')) exit();
define('DB_NAME', 'Database-Name');
define('DB_USER', 'Database-User');
define('DB_PASSWORD', 'Database-Password');
define('DB_HOST', 'Database-Host');
define('WP_DEBUG', true);
define('WP_HOME', 'https://dev.local');
define('WP_SITEURL', 'https://dev.local');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment