Ticket #5473: wpdb_errors.diff

File wpdb_errors.diff, 4.5 KB (added by ryan, 4 years ago)
  • wp-includes/wp-db.php

     
    1515 
    1616class wpdb { 
    1717 
    18         var $show_errors = true; 
     18        var $show_errors = false; 
    1919        var $num_queries = 0; 
    2020        var $last_query; 
    2121        var $col_info; 
     
    170170                $EZSQL_ERROR[] = 
    171171                array ('query' => $this->last_query, 'error_str' => $str); 
    172172 
     173                $error_str = "WordPress database error $str for query $this->last_query"; 
     174                if ( $caller = $this->get_caller() ) 
     175                        $error_str .= " made by $caller"; 
     176                error_log($error_str, 0); 
     177 
     178                // Is error output turned on or not.. 
     179                if ( !$this->show_errors ) 
     180                        return false; 
     181 
    173182                $str = htmlspecialchars($str, ENT_QUOTES); 
    174183                $query = htmlspecialchars($this->last_query, ENT_QUOTES); 
    175                 // Is error output turned on or not.. 
    176                 if ( $this->show_errors ) { 
    177                         // If there is an error then take note of it 
    178                         print "<div id='error'> 
    179                         <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br /> 
    180                         <code>$query</code></p> 
    181                         </div>"; 
    182                 } else { 
    183                         return false; 
    184                 } 
     184 
     185                // If there is an error then take note of it 
     186                print "<div id='error'> 
     187                <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br /> 
     188                <code>$query</code></p> 
     189                </div>"; 
    185190        } 
    186191 
    187192        // ================================================================== 
    188193        //      Turn error handling on or off.. 
    189194 
    190         function show_errors() { 
    191                 $this->show_errors = true; 
     195        function show_errors( $show = true ) { 
     196                $errors = $this->show_errors; 
     197                $this->show_errors = $show; 
     198                return $errors; 
    192199        } 
    193200 
    194201        function hide_errors() { 
     202                $show = $this->show_errors; 
    195203                $this->show_errors = false; 
     204                return $show; 
    196205        } 
    197206 
    198207        // ================================================================== 
  • wp-includes/functions.php

     
    206206 
    207207                if ( false === $value ) { 
    208208                        if ( defined( 'WP_INSTALLING' ) ) 
    209                                 $wpdb->hide_errors(); 
     209                                $show = $wpdb->hide_errors(); 
    210210                        // expected_slashed ($setting) 
    211211                        $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" ); 
    212212                        if ( defined( 'WP_INSTALLING' ) ) 
    213                                 $wpdb->show_errors(); 
     213                                $wpdb->show_errors($show); 
    214214 
    215215                        if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 
    216216                                $value = $row->option_value; 
     
    246246 
    247247function get_alloptions() { 
    248248        global $wpdb, $wp_queries; 
    249         $wpdb->hide_errors(); 
     249        $show = $wpdb->hide_errors(); 
    250250        if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) ) 
    251251                $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); 
    252         $wpdb->show_errors(); 
     252        $wpdb->show_errors($show); 
    253253 
    254254        foreach ( $options as $option ) { 
    255255                // "When trying to design a foolproof system, 
     
    269269        $alloptions = wp_cache_get( 'alloptions', 'options' ); 
    270270 
    271271        if ( !$alloptions ) { 
    272                 $wpdb->hide_errors(); 
     272                $show = $wpdb->hide_errors(); 
    273273                if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) ) 
    274274                        $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); 
    275                 $wpdb->show_errors(); 
     275                $wpdb->show_errors($show); 
    276276                $alloptions = array(); 
    277277                foreach ( (array) $alloptions_db as $o ) 
    278278                        $alloptions[$o->option_name] = $o->option_value; 
     
    913913        if ( wp_cache_get('is_blog_installed') ) 
    914914                return true; 
    915915 
    916         $wpdb->hide_errors(); 
     916        $show = $wpdb->hide_errors(); 
    917917        $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); 
    918         $wpdb->show_errors(); 
     918        $wpdb->show_errors($show); 
    919919 
    920920        $installed = !empty( $installed ) ? true : false; 
    921921        wp_cache_set('is_blog_installed', $installed); 
  • wp-includes/user.php

     
    236236function _fill_user( &$user ) { 
    237237        global $wpdb; 
    238238 
    239         $wpdb->hide_errors(); 
     239        $show = $wpdb->hide_errors(); 
    240240        $metavalues = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = %d", $user->ID)); 
    241         $wpdb->show_errors(); 
     241        $wpdb->show_errors($show); 
    242242 
    243243        if ( $metavalues ) { 
    244244                foreach ( $metavalues as $meta ) {