Created
June 21, 2016 12:40
-
-
Save christianwach/ff07358a7fde4b2b7c7df5973f673449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Clone of wp_debug_backtrace_summary() | |
* | |
* Return a comma-separated string of functions that have been called to get | |
* to the current point in code. | |
* | |
* @see https://core.trac.wordpress.org/ticket/19589 | |
* | |
* @param string $ignore_class Optional. A class to ignore all function calls within - useful | |
* when you want to just give info about the callee. Default null. | |
* @param int $skip_frames Optional. A number of stack frames to skip - useful for unwinding | |
* back to the source of the issue. Default 0. | |
* @param bool $pretty Optional. Whether or not you want a comma separated string or raw | |
* array returned. Default true. | |
* @return string|array Either a string containing a reversed comma separated trace or an array | |
* of individual calls. | |
*/ | |
function cmw_wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) { | |
if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) | |
$trace = debug_backtrace( false ); | |
else | |
$trace = debug_backtrace(); | |
$caller = array(); | |
$check_class = ! is_null( $ignore_class ); | |
$skip_frames++; // skip this function | |
foreach ( $trace as $call ) { | |
$line = (isset($call['line']) ? ' line:' . $call['line'] : ' <unknown line>'); | |
if ( $skip_frames > 0 ) { | |
$skip_frames--; | |
} elseif ( isset( $call['class'] ) ) { | |
if ( $check_class && $ignore_class == $call['class'] ) | |
continue; // Filter out calls | |
$caller[] = "{$call['class']}{$call['type']}{$call['function']}" . $line; | |
} else { | |
if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) { | |
$caller[] = "{$call['function']}('{$call['args'][0]}')" . $line; | |
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) { | |
$caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')" . $line; | |
} else { | |
$caller[] = $call['function'] . $line; | |
} | |
} | |
} | |
if ( $pretty ) | |
return join( ', ', array_reverse( $caller ) ); | |
else | |
return $caller; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment