Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Error handler with WordPress backtrace in message.
<?php
set_error_handler( 'backtrace_error_handler', error_reporting() );
function backtrace_error_handler( $errno, $errstr, $errfile, $errline, $errcontext ) {
// handle @
if( 0 === error_reporting() )
return false;
$message = $errstr . ' in ' . $errfile . ' on line ' . $errline . ', backtrace: ' . wp_debug_backtrace_summary( null, 1 );
if( WP_DEBUG_DISPLAY || ini_get( 'display_errors' ) )
echo '<br />' . $message . '<br />';
if( WP_DEBUG_LOG || ini_get( 'log_errors' ) )
error_log( $message );
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment