Permalink
Browse files

Move database class loading to a shared function to ensure all of Wor…

…dPress is wp-content/wp-db.php aware. Fixes #5128 props ComputerGuru.

git-svn-id: http://svn.automattic.com/wordpress/tags/2.3@6196 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
1 parent d20349b commit 7785eaddd78c2b594b76a22d4fe013fb5c613d64 westi committed Oct 6, 2007
Showing with 22 additions and 6 deletions.
  1. +4 −1 wp-admin/setup-config.php
  2. +17 −0 wp-includes/functions.php
  3. +1 −5 wp-settings.php
View
5 wp-admin/setup-config.php
@@ -1,5 +1,8 @@
<?php
define('WP_INSTALLING', true);
+//These two defines are required to allow us to use require_wp_db() to load the database class while being wp-content/wp-db.php aware
+define('ABSPATH', dirname(__FILE__).'/../');
+define('WPINC', 'wp-includes');
require_once('../wp-includes/compat.php');
require_once('../wp-includes/functions.php');
@@ -160,7 +163,7 @@ function display_header(){
define('DB_HOST', $dbhost);
// We'll fail here if the values are no good.
- require_once('../wp-includes/wp-db.php');
+ require_wp_db();
$handle = fopen('../wp-config.php', 'w');
foreach ($configFile as $line_num => $line) {
View
17 wp-includes/functions.php
@@ -1416,4 +1416,21 @@ function wp_ob_end_flush_all()
while ( @ob_end_flush() );
}
+/*
+ * require_wp_db() - require_once the correct database class file.
+ *
+ * This function is used to load the database class file either at runtime or by wp-admin/setup-config.php
+ * We must globalise $wpdb to ensure that it is defined globally by the inline code in wp-db.php
+ *
+ * @global $wpdb
+ */
+function require_wp_db()
+{
+ global $wpdb;
+ if ( file_exists(ABSPATH . 'wp-content/db.php') )
+ require_once (ABSPATH . 'wp-content/db.php');
+ else
+ require_once (ABSPATH . WPINC . '/wp-db.php');
+}
+
?>
View
6 wp-settings.php
@@ -117,11 +117,7 @@ function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(
require (ABSPATH . WPINC . '/compat.php');
require (ABSPATH . WPINC . '/functions.php');
-if ( file_exists(ABSPATH . 'wp-content/db.php') )
- require_once (ABSPATH . 'wp-content/db.php');
-else
- require_once (ABSPATH . WPINC . '/wp-db.php');
-
+require_wp_db();
// $table_prefix is deprecated as of 2.1
$wpdb->prefix = $table_prefix;

0 comments on commit 7785ead

Please sign in to comment.