From 9e97f2524911ba2420bf59e996e44b9f09ce984d Mon Sep 17 00:00:00 2001 From: nacin Date: Mon, 20 Sep 2010 19:13:47 +0000 Subject: [PATCH] Always include wp-db.php. Prevents a conditional include and allows db dropins to cleanly extend the wpdb class. Move require_wp_db() to load.php for consistency with bootloader helpers. fixes #14508. git-svn-id: http://svn.automattic.com/wordpress/trunk@15638 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 18 ------------------ wp-includes/load.php | 23 +++++++++++++++++++++++ wp-includes/wp-db.php | 8 -------- wp-settings.php | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3b4e4012e2..7443acdc1d 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3100,24 +3100,6 @@ function wp_ob_end_flush_all() { ob_end_flush(); } -/** - * Load 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. - * - * @since 2.5.0 - * @global $wpdb WordPress Database Object - */ -function require_wp_db() { - global $wpdb; - if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) - require_once( WP_CONTENT_DIR . '/db.php' ); - else - require_once( ABSPATH . WPINC . '/wp-db.php' ); -} - /** * Load custom DB error or display WordPress DB error. * diff --git a/wp-includes/load.php b/wp-includes/load.php index 05415485d0..03b9942904 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -307,6 +307,29 @@ function wp_set_lang_dir() { } } +/** + * Load 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 globalize $wpdb to ensure that it is + * defined globally by the inline code in wp-db.php. + * + * @since 2.5.0 + * @global $wpdb WordPress Database Object + */ +function require_wp_db() { + global $wpdb; + + require_once( ABSPATH . WPINC . '/wp-db.php' ); + if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) + require_once( WP_CONTENT_DIR . '/db.php' ); + + if ( isset( $wpdb ) ) + return; + + $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); +} + /** * Sets the database table prefix and the format specifiers for database table columns. * diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 818cd3fa32..1f6228434e 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1554,12 +1554,4 @@ class wpdb { } } -if ( ! isset( $wpdb ) ) { - /** - * WordPress Database Object, if it isn't set already in wp-content/db.php - * @global object $wpdb Creates a new wpdb object based on wp-config.php Constants for the database - * @since 0.71 - */ - $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); -} ?> diff --git a/wp-settings.php b/wp-settings.php index 473f2c6cdd..bdfc58a5cb 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -67,7 +67,7 @@ require( ABSPATH . WPINC . '/compat.php' ); require( ABSPATH . WPINC . '/functions.php' ); require( ABSPATH . WPINC . '/classes.php' ); -// Include the wpdb class, or a db.php database drop-in if present. +// Include the wpdb class and, if present, a db.php database drop-in. require_wp_db(); // Set the database table prefix and the format specifiers for database table columns.