Make WordPress Core

Changeset 19773


Ignore:
Timestamp:
01/28/2012 11:56:50 AM (15 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

Location:
trunk/wp-includes
Files:
2 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}
  • trunk/wp-includes/wp-db.php

    r19760 r19773  
    15461546         */
    15471547        function get_caller() {
    1548                 $trace  = array_reverse( debug_backtrace() );
    1549                 $caller = array();
    1550 
    1551                 foreach ( $trace as $call ) {
    1552                         if ( isset( $call['class'] ) && __CLASS__ == $call['class'] )
    1553                                 continue; // Filter out wpdb calls.
    1554                         $caller[] = isset( $call['class'] ) ? "{$call['class']}->{$call['function']}" : $call['function'];
    1555                 }
    1556 
    1557                 return join( ', ', $caller );
     1548                return wp_debug_backtrace_summary( __CLASS__ );
    15581549        }
    15591550
Note: See TracChangeset for help on using the changeset viewer.