Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Forked from markjaquith/wp-config.php
Created April 20, 2016 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/64fe6945a1d9b55504f80288e2aa0804 to your computer and use it in GitHub Desktop.
Save wpsmith/64fe6945a1d9b55504f80288e2aa0804 to your computer and use it in GitHub Desktop.
`wp-config.php` file to sit above a pristine WordPress directory, whereby the site can symlink their WP directory to a common one, and this file will make sure their `wp-config.php` is the one that gets called. Untested in production. Just an idea right now.
<?php
$path = str_replace( $_SERVER['DOCUMENT_ROOT'], '', dirname( $_SERVER['SCRIPT_FILENAME'] ) );
$path_parts = explode( '/', $path );
while ( count( $path_parts ) > 0 ) {
$path = $_SERVER['DOCUMENT_ROOT'] . implode( '/', $path_parts ) . '/wp-config.php';
if ( file_exists( $path ) ) {
include( $path );
break;
} else {
array_pop( $path_parts );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment