Skip to content

Instantly share code, notes, and snippets.

@markjaquith
Created August 12, 2013 20:19
Show Gist options
  • Save markjaquith/6214749 to your computer and use it in GitHub Desktop.
Save markjaquith/6214749 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 );
}
}
@leoj3n
Copy link

leoj3n commented Aug 14, 2013

<?php
$p = $_SERVER['SCRIPT_FILENAME'];
while ($p !== $_SERVER['DOCUMENT_ROOT'])
  if (@include(($p = dirname($p)).'/wp-config.php')) break;

@markjaquith
Copy link
Author

@leoj3n — Oh my. Don't love @-suppression, but even with a file_exists() check, that's much shorter. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment