Debugging WordPress

Since I’m making use of WordPress for this blog I figured I’d spend some time debugging it and send in the patches. To assist in tracking down the bugs I made a small addition to wp-config.php:


function wp_error_handler(
    $errno,
    $errstr,
    $errfile,
    $errline
) {
    error_log(
        "WordPress Error: " .
        "errno: {$errno} " .
        "errstr: {$errstr} " .
        "errfile: {$errfile} " .
        "errline: {$errline} " .
        var_export(debug_backtrace())
    );
    return(true);
}
set_error_handler('wp_error_handler');

It isn’t the most elegant logging mechanism, but it does make errors show pretty obviously. Most of the errors that have come up so far are use of variables that doesn’t exist. I’d recommend NOT using this on a live site.