Get a human-readable debug backtrace including the the file, the function which calls it, and its line number.
/** * Returns a human readable line by line backtrace * including the file, function which calls, and the line #. */ function isa_get_backtrace() { $o = ''; $file = ''; $func = ''; $line = ''; $trace = debug_backtrace(); foreach ( $trace as $each ) { if ( isset( $each['file'] ) ) $file = $each['file']; if ( isset( $each['function'] ) ) $func = $each['function']; if ( isset( $each['line'] ) ) $line = $each['line']; $o .= $file . ": "; $o .= ($func != '') ? $func . "(): " : ""; $o .= ($line != '') ? $line . "\n" : "\n"; } return($o); }
Usage:
The following will print it directly to your WordPress error log (/wp-content/debug.log
).
error_log( isa_get_backtrace() );
Questions and Comments are Welcome