diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 6da652e58a..d5d1b7fc2d 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -198,10 +198,10 @@ function get_option($setting) { if ( false === $value ) { if ( defined('WP_INSTALLING') ) - $wpdb->hide_errors(); + $show = $wpdb->hide_errors(); $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1"); if ( defined('WP_INSTALLING') ) - $wpdb->show_errors(); + $wpdb->show_errors($show); if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values $value = $row->option_value; @@ -236,11 +236,11 @@ function form_option($option) { function get_alloptions() { global $wpdb, $wp_queries; - $wpdb->hide_errors(); + $show = $wpdb->hide_errors(); if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) { $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); } - $wpdb->show_errors(); + $wpdb->show_errors($show); foreach ($options as $option) { // "When trying to design a foolproof system, @@ -263,10 +263,10 @@ function wp_load_alloptions() { $alloptions = wp_cache_get('alloptions', 'options'); if ( !$alloptions ) { - $wpdb->hide_errors(); + $show = $wpdb->hide_errors(); if ( !$alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) $alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options"); - $wpdb->show_errors(); + $wpdb->show_errors($show); $alloptions = array(); foreach ( (array) $alloptions_db as $o ) $alloptions[$o->option_name] = $o->option_value; @@ -892,9 +892,9 @@ function do_robots() { function is_blog_installed() { global $wpdb; - $wpdb->hide_errors(); + $show = $wpdb->hide_errors(); $installed = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'"); - $wpdb->show_errors(); + $wpdb->show_errors($show); $install_status = !empty( $installed ) ? TRUE : FALSE; return $install_status; diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index cfeabeeb2c..32281e67d7 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -72,9 +72,9 @@ function get_userdata( $user_id ) { if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id' LIMIT 1") ) return false; - $wpdb->hide_errors(); + $show = $wpdb->hide_errors(); $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'"); - $wpdb->show_errors(); + $wpdb->show_errors($show); if ($metavalues) { foreach ( $metavalues as $meta ) { diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index a2b98c7c66..65808311c5 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -15,7 +15,7 @@ if (!defined('SAVEQUERIES')) class wpdb { - var $show_errors = true; + var $show_errors = false; var $num_queries = 0; var $last_query; var $col_info; @@ -149,29 +149,38 @@ class wpdb { $EZSQL_ERROR[] = array ('query' => $this->last_query, 'error_str' => $str); + $error_str = "WordPress database error $str for query $this->last_query"; + if ( $caller = $this->get_caller() ) + $error_str .= " made by $caller"; + error_log($error_str, 0); + + // Is error output turned on or not.. + if ( !$this->show_errors ) + return false; + $str = htmlspecialchars($str, ENT_QUOTES); $query = htmlspecialchars($this->last_query, ENT_QUOTES); - // Is error output turned on or not.. - if ( $this->show_errors ) { - // If there is an error then take note of it - print "
-

WordPress database error: [$str]
- $query

-
"; - } else { - return false; - } + + // If there is an error then take note of it + print "
+

WordPress database error: [$str]
+ $query

+
"; } // ================================================================== // Turn error handling on or off.. - function show_errors() { - $this->show_errors = true; + function show_errors( $show = true ) { + $errors = $this->show_errors; + $this->show_errors = $show; + return $errors; } function hide_errors() { + $show = $this->show_errors; $this->show_errors = false; + return $show; } // ==================================================================