Make WordPress Core


Ignore:
Timestamp:
01/28/2012 11:56:50 AM (12 years ago)
Author:
westi
Message:

Refactor WPDB::get_caller() into wp_debug_backtrace_summary() and improve the functionality to provide enhanced context and a standardised default pretty format. Fixes #19589

File:
1 edited

Legend:

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

    r19760 r19773  
    36593659    return $protocols;
    36603660}
     3661
     3662/**
     3663 * Return a comma seperated string of functions that have been called to get to the current point in code.
     3664 * @link http://core.trac.wordpress.org/ticket/19589
     3665 * @since 3.4
     3666 *
     3667 * @param string $ignore_class A class to ignore all function calls within - useful when you want to just give info about the calllee
     3668 * @param string $skip_frames A number of stack frames to skip - useful for unwinding back to the source of the issue
     3669 * @param bool $pretty Whether or not you want a comma seperated string or raw array returned
     3670 * @return string|array Either a string containing a reversed comma seperated trace or an array of individual calls.
     3671 */
     3672function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
     3673    $trace  = debug_backtrace( false );
     3674    $caller = array();
     3675    $check_class = ! is_null( $ignore_class );
     3676    $skip_frames++; // skip this function
     3677
     3678    foreach ( $trace as $call ) {
     3679        if ( $skip_frames > 0 ) {
     3680            $skip_frames--;
     3681        } elseif ( isset( $call['class'] ) ) {
     3682            if ( $check_class && $ignore_class == $call['class'] )
     3683                continue; // Filter out calls
     3684
     3685            $caller[] = "{$call['class']}{$call['type']}{$call['function']}";
     3686        } else {
     3687            if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) {
     3688                $caller[] = "{$call['function']}('{$call['args'][0]}')";
     3689            } elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
     3690                $caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')";
     3691            } else {
     3692                $caller[] = $call['function'];
     3693            }
     3694        }
     3695    }
     3696    if ( $pretty )
     3697        return join( ', ', array_reverse( $caller ) );
     3698    else
     3699        return $caller;
     3700}
Note: See TracChangeset for help on using the changeset viewer.