Skip to content

Instantly share code, notes, and snippets.

@wpsmithtwc
Forked from markjaquith/wp-config.php
Created April 25, 2016 14:53
Show Gist options
  • Save wpsmithtwc/b31f99fb8a0704572454962bbe6b99f6 to your computer and use it in GitHub Desktop.
Save wpsmithtwc/b31f99fb8a0704572454962bbe6b99f6 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