Skip to content

Instantly share code, notes, and snippets.

@retgef
Last active December 11, 2015 02:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save retgef/4534979 to your computer and use it in GitHub Desktop.
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.
<?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