Skip to content

Instantly share code, notes, and snippets.

@timwhitlock
Created January 27, 2012 10:48
Show Gist options
  • Save timwhitlock/1688245 to your computer and use it in GitHub Desktop.
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
<?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 );
}
}
@johnbillion
Copy link

Sorry, got tripped up by the comment editor there.

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