Last active
December 11, 2015 02:59
-
-
Save retgef/4534979 to your computer and use it in GitHub Desktop.
For use with multiple sub-folder WordPress installations. This allows you to store all wp-config.php in any folder on your server. WP config files are renamed to correspond with the server name. This approach helps you protect your wp-config files when you have multiple docroots in one folder.
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
<?php | |
# ------------------ | |
# no shenanigans | |
# ------------------ | |
if ( __FILE__ == $_SERVER['SCRIPT_FILENAME'] ) { die(); } | |
# --------------- | |
# server name | |
# --------------- | |
$server = $_SERVER['SERVER_NAME']; | |
# ----------------------- | |
# wp-config directory | |
# ----------------------- | |
$configs_dir = dirname( __FILE__ ); | |
# ---------------------------- | |
# config file name | |
# example: dev_mydomain_com | |
# ----------------------------- | |
$file_name = str_replace( '.', '_', $server ); | |
# -------------------- | |
# config file path | |
# -------------------- | |
$config_path = "$config_path/$server.php"; | |
# ------------------------------ | |
# set ABSPATH to proper path | |
# ------------------------------ | |
if( !defined( 'ABSPATH' ) ) | |
define( 'ABSPATH', dirname( __FILE__ ) . '/' ); | |
# ------------------------------- | |
# load domain-specific config | |
# ------------------------------- | |
if( file_exists( $config_path ) ) | |
require_once( $config_path ); | |
else | |
throw new Exception( "No config file could be found at: $config_path" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment