Skip to content

Instantly share code, notes, and snippets.

@jrfnl
Last active March 13, 2025 10:13
Show Gist options
  • Select an option

  • Save jrfnl/5925642 to your computer and use it in GitHub Desktop.

Select an option

Save jrfnl/5925642 to your computer and use it in GitHub Desktop.

Revisions

  1. jrfnl revised this gist May 13, 2016. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -107,8 +107,11 @@
    */
    if ( ! function_exists( 'jrf_process_error_backtrace' ) ) {
    function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    // Only show errors which are within the scope of the current error_reporting() setting.
    // As WP (and plugins/themes) sometimes change the error level, you may want to comment this out.
    /*
    * Only show errors which are within the scope of the current error_reporting() setting.
    * As WP (and plugins/themes) sometimes change the error level, you may want to comment
    * this out if you want to be sure to see all errors.
    */
    if( ! ( error_reporting() & $errno ) ) {
    return;
    }
  2. jrfnl revised this gist May 13, 2016. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -107,6 +107,12 @@
    */
    if ( ! function_exists( 'jrf_process_error_backtrace' ) ) {
    function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    // Only show errors which are within the scope of the current error_reporting() setting.
    // As WP (and plugins/themes) sometimes change the error level, you may want to comment this out.
    if( ! ( error_reporting() & $errno ) ) {
    return;
    }

    /**
    * Make sure all error levels are present. PHP 5.2 compatibility.
    */
  3. jrfnl revised this gist May 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -139,7 +139,7 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    if ( php_sapi_name() == 'cli' && ini_get( 'display_errors' ) ) {
    echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    foreach ( $trace as $item ) {
    echo ' ' . ( isset( $item['file'] ) ? $item['file'] : '<unknown file>') . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()' . "\n";
    echo ' ' . ( isset( $item['file'] ) ? $item['file'] : '<unknown file>' ) . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()' . "\n";
    }
    }
    elseif ( ini_get( 'display_errors' ) ) {
    @@ -158,7 +158,7 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    $items[] = ( isset( $item['file'] ) ? $item['file'] : '<unknown file>' ) . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()';
    }
    $message = 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ': ' . trim( join( ' | ', $items ) );
    error_log($message);
    error_log( $message );
    }

    flush();
  4. jrfnl revised this gist May 12, 2016. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -84,7 +84,7 @@
    @ini_set( 'error_log', '/path/to/writable/file/logs/error.log' );

    if ( WP_DEBUG !== true ) {
    @ini_set( 'display_errors', false ); // Don't show errors on screen
    @ini_set( 'display_errors', false ); // Don't show errors on screen
    }
    else {
    @ini_set( 'display_errors', true ); // Show errors on screen
    @@ -118,7 +118,7 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    }


    switch($errno) {
    switch ( $errno ) {
    case E_WARNING :
    case E_USER_WARNING :
    case E_STRICT :
    @@ -135,7 +135,7 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    break;
    }
    $trace = debug_backtrace();
    array_shift($trace);
    array_shift( $trace );
    if ( php_sapi_name() == 'cli' && ini_get( 'display_errors' ) ) {
    echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    foreach ( $trace as $item ) {
    @@ -152,9 +152,9 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    }
    echo '</ol>' . "\n";
    }
    if( ini_get( 'log_errors' ) ) {
    if ( ini_get( 'log_errors' ) ) {
    $items = array();
    foreach( $trace as $item ) {
    foreach ( $trace as $item ) {
    $items[] = ( isset( $item['file'] ) ? $item['file'] : '<unknown file>' ) . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()';
    }
    $message = 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ': ' . trim( join( ' | ', $items ) );
    @@ -163,7 +163,7 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {

    flush();

    if( $fatal ) {
    if ( $fatal ) {
    exit( 1 );
    }

  5. jrfnl revised this gist May 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -126,11 +126,11 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    case E_USER_NOTICE :
    case E_DEPRECATED :
    case E_USER_DEPRECATED :
    $type = 'warning';
    $type = 'warning';
    $fatal = false;
    break;
    default :
    $type = 'fatal error';
    $type = 'fatal error';
    $fatal = true;
    break;
    }
  6. jrfnl revised this gist May 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -146,11 +146,11 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    echo '<p class="error_backtrace">' . "\n";
    echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    echo '</p>' . "\n";
    echo ' <ol class="error_backtrace_list">' . "\n";
    echo '<ol class="error_backtrace_list">' . "\n";
    foreach ( $trace as $item ) {
    echo ' <li>' . ( isset( $item['file'] ) ? $item['file'] : '<unknown file>' ) . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()</li>' . "\n";
    }
    echo ' </ol>' . "\n";
    echo '</ol>' . "\n";
    }
    if( ini_get( 'log_errors' ) ) {
    $items = array();
  7. jrfnl revised this gist May 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -145,12 +145,12 @@ function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    elseif ( ini_get( 'display_errors' ) ) {
    echo '<p class="error_backtrace">' . "\n";
    echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    echo ' <ol>' . "\n";
    echo '</p>' . "\n";
    echo ' <ol class="error_backtrace_list">' . "\n";
    foreach ( $trace as $item ) {
    echo ' <li>' . ( isset( $item['file'] ) ? $item['file'] : '<unknown file>' ) . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()</li>' . "\n";
    }
    echo ' </ol>' . "\n";
    echo '</p>' . "\n";
    }
    if( ini_get( 'log_errors' ) ) {
    $items = array();
  8. jrfnl revised this gist May 12, 2016. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -107,10 +107,6 @@
    */
    if ( ! function_exists( 'jrf_process_error_backtrace' ) ) {
    function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    if( ! ( error_reporting() & $errno ) ) {
    return;
    }

    /**
    * Make sure all error levels are present. PHP 5.2 compatibility.
    */
  9. jrfnl revised this gist Apr 29, 2016. 1 changed file with 121 additions and 57 deletions.
    178 changes: 121 additions & 57 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -8,15 +8,17 @@
    *
    * Oh.. and *do* make sure you change the path to the log file to a proper file path on your server (make sure it exists).
    *
    * Set WP_DEBUG to false if you don't want errors displayed on the screen.
    * Independently of the WP_DEBUG setting, PHP errors, warnings and notices should now appear in your error.log file.
    * Set WP_DEBUG_DISPLAY to false if you don't want errors displayed on the screen.
    * Independently of the WP_DEBUG settings, PHP errors, warnings and notices should now appear in your error.log file.
    *
    * == DO == test whether it's all working by using the code at the end of the gist.
    *
    * If error logging is not working, try:
    * - Check if the file was created at all, if not, upload an empty (text) file named error.log and try again.
    * - Fiddle around with the CHMOD settings for the error.log file to see what permissions are needed for your server setup.
    * - If you put the error.log outside of the web root: this will not work in all server setups. You may need to move the directory & file to be within the web root.
    *
    * Source: https://gist.github.com/jrfnl/5925642
    */


    @@ -27,21 +29,59 @@
    * It is strongly recommended that plugin and theme developers use WP_DEBUG
    * in their development environments.
    */
    define('WP_DEBUG', true);

    /**
    * Turn on error logging and show errors on-screen if in debugging mode
    * Turn on WP error reporting.
    */
    define( 'WP_DEBUG', true );



    /**
    * [Optional] Load the development (non-minified) versions of all standard WP scripts and CSS, and disables compression and concatenation.
    *
    * This setting is often also respected by themes and plugins, but no guarantee!
    */
    // define( 'SCRIPT_DEBUG', true );


    /**
    * [Optional] Save queries for analysis
    * The SAVEQUERIES definition saves the database queries to an array and that array
    * can be displayed to help analyze those queries. The information saves each query,
    * what function called it, and how long that query took to execute.
    *
    * NOTE: This will have a performance impact on your site, so make sure to turn this
    * off when you aren't debugging.
    *
    * To get access to the information, you can add the following snippet to the footer of your theme:
    *
    * <?php
    * if ( current_user_can( 'administrator' ) ) {
    * global $wpdb;
    * echo "<pre>";
    * print_r($wpdb->queries);
    * echo "</pre>";
    * }
    * ?>
    */
    // define('SAVEQUERIES', true);



    /**
    * Turn on error logging and show errors on-screen if in debugging mode.
    */
    @error_reporting( E_ALL );
    @ini_set('log_errors', true);
    @ini_set('log_errors_max_len', '0');
    @error_reporting( -1 ); // everything, including E_STRICT and other newly introduced error levels.
    @ini_set( 'log_errors', true );
    @ini_set( 'log_errors_max_len', '0' );

    /**
    * Change the path to one on your webserver, the directory does not have to be in the web root
    * Don't forget to CHMOD this dir+file and add an .htaccess file denying access to all
    * For an example .htaccess file, see https://gist.github.com/jrfnl/5953256
    */
    @ini_set('error_log', '/path/to/writable/file/logs/error.log');
    @ini_set( 'error_log', '/path/to/writable/file/logs/error.log' );

    if ( WP_DEBUG !== true ) {
    @ini_set( 'display_errors', false ); // Don't show errors on screen
    @@ -51,68 +91,92 @@
    @ini_set( 'html_errors', true );
    @ini_set( 'docref_root', 'http://php.net/manual/' );
    @ini_set( 'docref_ext', '.php' );
    @ini_set( 'error_prepend_string', '<span style="color: #ff0000; background-color: transparent;">' );
    @ini_set( 'error_append_string', '</span>' );
    if ( ! extension_loaded( 'xdebug' ) ) {
    @ini_set( 'error_prepend_string', '<span style="color: #ff0000; background-color: transparent;">' );
    @ini_set( 'error_append_string', '</span>' );
    }
    }


    /**
    * Adds a backtrace to PHP errors
    * Adds a backtrace to PHP errors.
    *
    * Copied from: https://gist.github.com/625769
    * Forked from: http://stackoverflow.com/questions/1159216/how-can-i-get-php-to-produce-a-backtrace-upon-errors/1159235#1159235
    * Adjusted by jrfnl
    * Adjusted by jrfnl.
    */
    function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    if(!(error_reporting() & $errno))
    return;
    switch($errno) {
    case E_WARNING :
    case E_USER_WARNING :
    case E_STRICT :
    case E_NOTICE :
    case ( defined( 'E_DEPRECATED' ) ? E_DEPRECATED : 8192 ) :
    case E_USER_NOTICE :
    $type = 'warning';
    $fatal = false;
    break;
    default :
    $type = 'fatal error';
    $fatal = true;
    break;
    }
    $trace = debug_backtrace();
    array_shift($trace);
    if(php_sapi_name() == 'cli' && ini_get('display_errors') ) {
    echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    foreach($trace as $item)
    echo ' ' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()' . "\n";

    if ( ! function_exists( 'jrf_process_error_backtrace' ) ) {
    function jrf_process_error_backtrace( $errno, $errstr, $errfile, $errline ) {
    if( ! ( error_reporting() & $errno ) ) {
    return;
    }

    /**
    * Make sure all error levels are present. PHP 5.2 compatibility.
    */
    if ( ! defined( 'E_DEPRECATED' ) ) {
    define( 'E_DEPRECATED', 8192 );
    }
    if ( ! defined( 'E_USER_DEPRECATED' ) ) {
    define( 'E_USER_DEPRECATED', 16384 );
    }


    switch($errno) {
    case E_WARNING :
    case E_USER_WARNING :
    case E_STRICT :
    case E_NOTICE :
    case E_USER_NOTICE :
    case E_DEPRECATED :
    case E_USER_DEPRECATED :
    $type = 'warning';
    $fatal = false;
    break;
    default :
    $type = 'fatal error';
    $fatal = true;
    break;
    }
    $trace = debug_backtrace();
    array_shift($trace);
    if ( php_sapi_name() == 'cli' && ini_get( 'display_errors' ) ) {
    echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    foreach ( $trace as $item ) {
    echo ' ' . ( isset( $item['file'] ) ? $item['file'] : '<unknown file>') . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()' . "\n";
    }
    }
    elseif ( ini_get( 'display_errors' ) ) {
    echo '<p class="error_backtrace">' . "\n";
    echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    echo ' <ol>' . "\n";
    foreach ( $trace as $item ) {
    echo ' <li>' . ( isset( $item['file'] ) ? $item['file'] : '<unknown file>' ) . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()</li>' . "\n";
    }
    echo ' </ol>' . "\n";
    echo '</p>' . "\n";
    }
    if( ini_get( 'log_errors' ) ) {
    $items = array();
    foreach( $trace as $item ) {
    $items[] = ( isset( $item['file'] ) ? $item['file'] : '<unknown file>' ) . ' ' . ( isset( $item['line'] ) ? $item['line'] : '<unknown line>' ) . ' calling ' . $item['function'] . '()';
    }
    $message = 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ': ' . trim( join( ' | ', $items ) );
    error_log($message);
    }

    flush();
    } else if( ini_get('display_errors') ) {
    echo '<p class="error_backtrace">' . "\n";
    echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    echo ' <ol>' . "\n";
    foreach($trace as $item)
    echo ' <li>' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()</li>' . "\n";
    echo ' </ol>' . "\n";
    echo '</p>' . "\n";

    flush();
    }
    if(ini_get('log_errors')) {
    $items = array();
    foreach($trace as $item)
    $items[] = (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()';
    $message = 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ': ' . join(' | ', $items);
    error_log($message);
    if( $fatal ) {
    exit( 1 );
    }

    return false; // Make sure it plays nice with other error handlers (remove if no other error handlers are set).
    }

    if($fatal)
    exit(1);
    set_error_handler( 'jrf_process_error_backtrace' );
    }

    set_error_handler('process_error_backtrace');

    /**
    * Now test whether it all works by uncommenting the below line
    @@ -121,4 +185,4 @@ function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    * - With WP_DEBUG set to true: You should see a red error notice on your screen
    * - Independently of the WP_DEBUG setting, the below 'error'-message should have been written to your log file. *Do* check whether it has been....
    */
    //trigger_error( 'Testing 1..2..3.. Debugging code is working!', E_USER_NOTICE );
    //trigger_error( 'Testing 1..2..3.. Debugging code is working!', E_USER_NOTICE );
  10. jrfnl revised this gist Dec 22, 2013. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -36,9 +36,11 @@
    @ini_set('log_errors', true);
    @ini_set('log_errors_max_len', '0');

    // Change the path to one on your webserver, the directory does not have to be in the web root
    // Don't forget to CHMOD this dir+file and add an .htaccess file denying access to all
    // For an example .htaccess file, see https://gist.github.com/jrfnl/5953256
    /**
    * Change the path to one on your webserver, the directory does not have to be in the web root
    * Don't forget to CHMOD this dir+file and add an .htaccess file denying access to all
    * For an example .htaccess file, see https://gist.github.com/jrfnl/5953256
    */
    @ini_set('error_log', '/path/to/writable/file/logs/error.log');

    if ( WP_DEBUG !== true ) {
  11. jrfnl revised this gist Dec 22, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    *
    * You would typically add this code below the database, language and salt settings
    *
    * Oh.. and *do* make sure you change the path to the log file to a proper file path on your server.
    * Oh.. and *do* make sure you change the path to the log file to a proper file path on your server (make sure it exists).
    *
    * Set WP_DEBUG to false if you don't want errors displayed on the screen.
    * Independently of the WP_DEBUG setting, PHP errors, warnings and notices should now appear in your error.log file.
  12. jrfnl revised this gist Oct 31, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -38,6 +38,7 @@

    // Change the path to one on your webserver, the directory does not have to be in the web root
    // Don't forget to CHMOD this dir+file and add an .htaccess file denying access to all
    // For an example .htaccess file, see https://gist.github.com/jrfnl/5953256
    @ini_set('error_log', '/path/to/writable/file/logs/error.log');

    if ( WP_DEBUG !== true ) {
  13. jrfnl revised this gist Oct 31, 2013. 1 changed file with 55 additions and 50 deletions.
    105 changes: 55 additions & 50 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -50,62 +50,67 @@
    @ini_set( 'docref_ext', '.php' );
    @ini_set( 'error_prepend_string', '<span style="color: #ff0000; background-color: transparent;">' );
    @ini_set( 'error_append_string', '</span>' );

    // Copied from: https://gist.github.com/625769
    // Forked from: http://stackoverflow.com/questions/1159216/how-can-i-get-php-to-produce-a-backtrace-upon-errors/1159235#1159235
    // Adjusted by jrfnl
    function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    if(!(error_reporting() & $errno))
    return;
    switch($errno) {
    case E_WARNING :
    case E_USER_WARNING :
    case E_STRICT :
    case E_NOTICE :
    case ( defined( 'E_DEPRECATED' ) ? E_DEPRECATED : 8192 ) :
    case E_USER_NOTICE :
    $type = 'warning';
    $fatal = false;
    break;
    default :
    $type = 'fatal error';
    $fatal = true;
    break;
    }
    $trace = debug_backtrace();
    array_shift($trace);
    if(php_sapi_name() == 'cli' && ini_get('display_errors') ) {
    echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    foreach($trace as $item)
    echo ' ' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()' . "\n";

    flush();
    } else if( ini_get('display_errors') ) {
    echo '<p class="error_backtrace">' . "\n";
    echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    echo ' <ol>' . "\n";
    foreach($trace as $item)
    echo ' <li>' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()</li>' . "\n";
    echo ' </ol>' . "\n";
    echo '</p>' . "\n";
    }


    flush();
    }
    if(ini_get('log_errors')) {
    $items = array();
    foreach($trace as $item)
    $items[] = (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()';
    $message = 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ': ' . join(' | ', $items);
    error_log($message);
    }
    /**
    * Adds a backtrace to PHP errors
    *
    * Copied from: https://gist.github.com/625769
    * Forked from: http://stackoverflow.com/questions/1159216/how-can-i-get-php-to-produce-a-backtrace-upon-errors/1159235#1159235
    * Adjusted by jrfnl
    */
    function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    if(!(error_reporting() & $errno))
    return;
    switch($errno) {
    case E_WARNING :
    case E_USER_WARNING :
    case E_STRICT :
    case E_NOTICE :
    case ( defined( 'E_DEPRECATED' ) ? E_DEPRECATED : 8192 ) :
    case E_USER_NOTICE :
    $type = 'warning';
    $fatal = false;
    break;
    default :
    $type = 'fatal error';
    $fatal = true;
    break;
    }
    $trace = debug_backtrace();
    array_shift($trace);
    if(php_sapi_name() == 'cli' && ini_get('display_errors') ) {
    echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    foreach($trace as $item)
    echo ' ' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()' . "\n";

    flush();
    } else if( ini_get('display_errors') ) {
    echo '<p class="error_backtrace">' . "\n";
    echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    echo ' <ol>' . "\n";
    foreach($trace as $item)
    echo ' <li>' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()</li>' . "\n";
    echo ' </ol>' . "\n";
    echo '</p>' . "\n";

    if($fatal)
    exit(1);
    flush();
    }
    if(ini_get('log_errors')) {
    $items = array();
    foreach($trace as $item)
    $items[] = (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()';
    $message = 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ': ' . join(' | ', $items);
    error_log($message);
    }

    set_error_handler('process_error_backtrace');
    if($fatal)
    exit(1);
    }

    set_error_handler('process_error_backtrace');

    /**
    * Now test whether it all works by uncommenting the below line
    *
  14. jrfnl revised this gist Jul 8, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@
    *
    * You would typically add this code below the database, language and salt settings
    *
    * Oh.. and *do* make sure you change the path to the log file to a proper file path on your server.
    *
    * Set WP_DEBUG to false if you don't want errors displayed on the screen.
    * Independently of the WP_DEBUG setting, PHP errors, warnings and notices should now appear in your error.log file.
    *
    @@ -51,7 +53,7 @@

    // Copied from: https://gist.github.com/625769
    // Forked from: http://stackoverflow.com/questions/1159216/how-can-i-get-php-to-produce-a-backtrace-upon-errors/1159235#1159235

    // Adjusted by jrfnl
    function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    if(!(error_reporting() & $errno))
    return;
  15. jrfnl revised this gist Jul 8, 2013. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -76,6 +76,8 @@ function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    foreach($trace as $item)
    echo ' ' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()' . "\n";

    flush();
    } else if( ini_get('display_errors') ) {
    echo '<p class="error_backtrace">' . "\n";
    echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    @@ -84,6 +86,8 @@ function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    echo ' <li>' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()</li>' . "\n";
    echo ' </ol>' . "\n";
    echo '</p>' . "\n";

    flush();
    }
    if(ini_get('log_errors')) {
    $items = array();
    @@ -93,8 +97,6 @@ function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    error_log($message);
    }

    flush();

    if($fatal)
    exit(1);
    }
  16. jrfnl revised this gist Jul 4, 2013. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,23 @@
    <?php
    /**
    * == About this Gist ==
    *
    * Code to add to wp-config.php to enhance information available for debugging.
    *
    * You would typically add this code below the database, language and salt settings
    *
    * Set WP_DEBUG to false if you don't want errors displayed on the screen.
    * Independently of the WP_DEBUG setting, PHP errors, warnings and notices should now appear in your error.log file.
    *
    * == DO == test whether it's all working by using the code at the end of the gist.
    *
    * If error logging is not working, try:
    * - Check if the file was created at all, if not, upload an empty (text) file named error.log and try again.
    * - Fiddle around with the CHMOD settings for the error.log file to see what permissions are needed for your server setup.
    * - If you put the error.log outside of the web root: this will not work in all server setups. You may need to move the directory & file to be within the web root.
    */


    /**
    * For developers: WordPress debugging mode.
    *
  17. jrfnl revised this gist Jul 4, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    /**
    * For developers: WordPress debugging mode.
    *
  18. jrfnl created this gist Jul 4, 2013.
    92 changes: 92 additions & 0 deletions wp-config-debug.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    /**
    * For developers: WordPress debugging mode.
    *
    * Change this to true to enable the display of notices during development.
    * It is strongly recommended that plugin and theme developers use WP_DEBUG
    * in their development environments.
    */
    define('WP_DEBUG', true);

    /**
    * Turn on error logging and show errors on-screen if in debugging mode
    */
    @error_reporting( E_ALL );
    @ini_set('log_errors', true);
    @ini_set('log_errors_max_len', '0');

    // Change the path to one on your webserver, the directory does not have to be in the web root
    // Don't forget to CHMOD this dir+file and add an .htaccess file denying access to all
    @ini_set('error_log', '/path/to/writable/file/logs/error.log');

    if ( WP_DEBUG !== true ) {
    @ini_set( 'display_errors', false ); // Don't show errors on screen
    }
    else {
    @ini_set( 'display_errors', true ); // Show errors on screen
    @ini_set( 'html_errors', true );
    @ini_set( 'docref_root', 'http://php.net/manual/' );
    @ini_set( 'docref_ext', '.php' );
    @ini_set( 'error_prepend_string', '<span style="color: #ff0000; background-color: transparent;">' );
    @ini_set( 'error_append_string', '</span>' );

    // Copied from: https://gist.github.com/625769
    // Forked from: http://stackoverflow.com/questions/1159216/how-can-i-get-php-to-produce-a-backtrace-upon-errors/1159235#1159235

    function process_error_backtrace($errno, $errstr, $errfile, $errline) {
    if(!(error_reporting() & $errno))
    return;
    switch($errno) {
    case E_WARNING :
    case E_USER_WARNING :
    case E_STRICT :
    case E_NOTICE :
    case ( defined( 'E_DEPRECATED' ) ? E_DEPRECATED : 8192 ) :
    case E_USER_NOTICE :
    $type = 'warning';
    $fatal = false;
    break;
    default :
    $type = 'fatal error';
    $fatal = true;
    break;
    }
    $trace = debug_backtrace();
    array_shift($trace);
    if(php_sapi_name() == 'cli' && ini_get('display_errors') ) {
    echo 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    foreach($trace as $item)
    echo ' ' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()' . "\n";
    } else if( ini_get('display_errors') ) {
    echo '<p class="error_backtrace">' . "\n";
    echo ' Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ':' . "\n";
    echo ' <ol>' . "\n";
    foreach($trace as $item)
    echo ' <li>' . (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()</li>' . "\n";
    echo ' </ol>' . "\n";
    echo '</p>' . "\n";
    }
    if(ini_get('log_errors')) {
    $items = array();
    foreach($trace as $item)
    $items[] = (isset($item['file']) ? $item['file'] : '<unknown file>') . ' ' . (isset($item['line']) ? $item['line'] : '<unknown line>') . ' calling ' . $item['function'] . '()';
    $message = 'Backtrace from ' . $type . ' \'' . $errstr . '\' at ' . $errfile . ' ' . $errline . ': ' . join(' | ', $items);
    error_log($message);
    }

    flush();

    if($fatal)
    exit(1);
    }

    set_error_handler('process_error_backtrace');
    }

    /**
    * Now test whether it all works by uncommenting the below line
    *
    * If all is well:
    * - With WP_DEBUG set to true: You should see a red error notice on your screen
    * - Independently of the WP_DEBUG setting, the below 'error'-message should have been written to your log file. *Do* check whether it has been....
    */
    //trigger_error( 'Testing 1..2..3.. Debugging code is working!', E_USER_NOTICE );