Make WordPress Core

Changeset 6342


Ignore:
Timestamp:
11/21/2007 12:14:58 AM (17 years ago)
Author:
ryan
Message:

Debug backtrace for queries. Props tellyworth. fixes #5218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/wp-db.php

    r6300 r6342  
    229229
    230230        if (SAVEQUERIES)
    231             $this->queries[] = array( $query, $this->timer_stop() );
     231            $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
    232232
    233233        // If there is an error then take note of it..
     
    476476        return ( version_compare(mysql_get_server_info(), '4.1.0', '>=') );
    477477    }
     478
     479    /**
     480     * Get the name of the function that called wpdb.
     481     * @return string the name of the calling function
     482     */
     483    function get_caller() {
     484        // requires PHP 4.3+
     485        if ( !is_callable('debug_backtrace') )
     486            return '';
     487
     488        $bt = debug_backtrace();
     489        $caller = '';
     490
     491        foreach ( $bt as $trace ) {
     492            if ( @$trace['class'] == __CLASS__ )
     493                continue;
     494            elseif ( strtolower(@$trace['function']) == 'call_user_func_array' )
     495                continue;
     496            elseif ( strtolower(@$trace['function']) == 'apply_filters' )
     497                continue;
     498            elseif ( strtolower(@$trace['function']) == 'do_action' )
     499                continue;
     500   
     501            $caller = $trace['function'];
     502            break;
     503        }
     504        return $caller;
     505    }
     506
    478507}
    479508
Note: See TracChangeset for help on using the changeset viewer.