Make WordPress Core

Ticket #5218: wpdb-get-caller-r6256.diff

File wpdb-get-caller-r6256.diff, 1.2 KB (added by tellyworth, 18 years ago)
  • wordpress/wp-includes/wp-db.php

     
    210210                ++$this->num_queries;
    211211
    212212                if (SAVEQUERIES)
    213                         $this->queries[] = array( $query, $this->timer_stop() );
     213                        $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
    214214
    215215                // If there is an error then take note of it..
    216216                if ( mysql_error($this->dbh) ) {
     
    457457        {
    458458                return ( version_compare(mysql_get_server_info(), '4.1.0', '>=') );
    459459        }
     460
     461        /**
     462         * Get the name of the function that called wpdb.
     463         * @return string the name of the calling function
     464         */
     465        function get_caller() {
     466                $bt = debug_backtrace();
     467                $caller = '';
     468
     469                foreach ($bt as $trace) {
     470                        if (@$trace['class'] == __CLASS__)
     471                                continue;
     472                        elseif (strtolower(@$trace['function']) == 'call_user_func_array')
     473                                continue;
     474                        elseif (strtolower(@$trace['function']) == 'apply_filters')
     475                                continue;
     476                        elseif (strtolower(@$trace['function']) == 'do_action')
     477                                continue;
     478       
     479                        $caller = $trace['function'];
     480                        break;
     481                }
     482                return $caller;
     483        }
     484
    460485}
    461486
    462487if ( ! isset($wpdb) )