Created
January 27, 2012 10:48
-
-
Save timwhitlock/1688245 to your computer and use it in GitHub Desktop.
What require_wp_db function in Wordpress would look like, if it worked
This file contains hidden or 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 | |
function require_wp_db() { | |
global $wpdb; | |
if ( isset($wpdb) ){ | |
return; | |
} | |
// Should check for override db.php file first | |
// - including both means fatal error on duplicate class | |
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ){ | |
require_once( WP_CONTENT_DIR . '/db.php' ); | |
} | |
// include core default | |
else { | |
require_once( ABSPATH . WPINC . '/wp-db.php' ); | |
} | |
// The db.php adapter may have defined the global for us | |
if( ! isset($wpdb) ){ | |
$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, got tripped up by the comment editor there.