compat.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. //Backcompat for pre this function making it into WordPress
  3. if ( ! function_exists( 'wp_debug_backtrace_summary' ) ) {
  4. /**
  5. * Return a comma separated string of functions that have been called to get to the current point in code.
  6. * @link http://core.trac.wordpress.org/ticket/19589
  7. * @since 3.4
  8. *
  9. * @param string $ignore_class A class to ignore all function calls within - useful when you want to just give info about the callee
  10. * @param string $skip_frames A number of stack frames to skip - useful for unwinding back to the source of the issue
  11. * @param bool $pretty Whether or not you want a comma separated string or raw array returned
  12. * @return string|array Either a string containing a reversed comma separated trace or an array of individual calls.
  13. */
  14. function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
  15. $trace = debug_backtrace( false );
  16. $caller = array();
  17. $check_class = ! is_null( $ignore_class );
  18. $skip_frames++; // skip this function
  19. foreach ( $trace as $call ) {
  20. if ( $skip_frames > 0 ) {
  21. $skip_frames--;
  22. } elseif ( isset( $call['class'] ) ) {
  23. if ( $check_class && $ignore_class == $call['class'] )
  24. continue; // Filter out calls
  25. $caller[] = "{$call['class']}{$call['type']}{$call['function']}";
  26. } else {
  27. if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) {
  28. $caller[] = "{$call['function']}('{$call['args'][0]}')";
  29. } elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
  30. $caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')";
  31. } else {
  32. $caller[] = $call['function'];
  33. }
  34. }
  35. }
  36. if ( $pretty )
  37. return join( ', ', array_reverse( $caller ) );
  38. else
  39. return $caller;
  40. }
  41. }
  42. ?>