Make WordPress Core

Ticket #19589: simpler-backtraces-core.diff

File simpler-backtraces-core.diff, 2.2 KB (added by westi, 12 years ago)

Implementation of a new wp_debug_backtrace_summary() function

  • wp-includes/functions.php

     
    46734673        return $protocols;
    46744674}
    46754675
    4676 ?>
     4676/**
     4677 * Return a comma seperated string of functions that have been called to get to the current point in code.
     4678 *
     4679 * @since 3.4
     4680 */
     4681function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0 ) {
     4682        // TODO: Maybe add version based switching for even less backtrace info
     4683        $trace  = debug_backtrace( false );
     4684        $caller = array();
     4685        $check_class = ! is_null( $ignore_class );
     4686        $skip_frames++; // skip this function
     4687
     4688        foreach ( $trace as $call ) {
     4689                if ( $skip_frames > 0 ) {
     4690                        $skip_frames--;
     4691                } elseif ( isset( $call['class'] ) ) {
     4692                        if ( $check_class && $ignore_class == $call['class'] )
     4693                                continue; // Filter out calls
     4694                       
     4695                        $caller[] = "{$call['class']}{$call['type']}{$call['function']}";
     4696                } else {
     4697                        if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) {
     4698                                $caller[] = "{$call['function']}('{$call['args'][0]}')";
     4699                        } elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
     4700                                $caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')";
     4701                        } else {
     4702                                $caller[] = $call['function'];
     4703                        }
     4704                }
     4705        }
     4706
     4707        return join( ', ', array_reverse( $caller ) );
     4708
     4709}
     4710
     4711?>
     4712 No newline at end of file
  • wp-includes/wp-db.php

     
    15461546         * @return string The name of the calling function
    15471547         */
    15481548        function get_caller() {
    1549                 $trace  = array_reverse( debug_backtrace() );
    1550                 $caller = array();
    1551 
    1552                 foreach ( $trace as $call ) {
    1553                         if ( isset( $call['class'] ) && __CLASS__ == $call['class'] )
    1554                                 continue; // Filter out wpdb calls.
    1555                         $caller[] = isset( $call['class'] ) ? "{$call['class']}->{$call['function']}" : $call['function'];
    1556                 }
    1557 
    1558                 return join( ', ', $caller );
     1549                return wp_debug_backtrace_summary( __CLASS__ );
    15591550        }
    15601551
    15611552        /**