Created
July 30, 2025 03:23
-
-
Save sc0ttkclark/fc9ec138162b6bc20f0aa78e88f10282 to your computer and use it in GitHub Desktop.
Custom PHP error handling for displaying fatal errors when they happen with a greater level of detail than normally shown for a site. Place this file at: wp-content/php-error.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom PHP error handling for displaying fatal errors when they happen with a greater level of detail than normally | |
* shown for a site. | |
* | |
* Place this file at: wp-content/php-error.php | |
* | |
* By default, it will fallback to the normal WP behavior for error pages/display. | |
* | |
* If using WP-CLI or setting `skcdebug=1` in the request (GET/POST/etc), then it will display the full error details. | |
* | |
* @var WP_Fatal_Error_Handler $this The fatal error handler instance that this file is loaded into the context for. | |
* @var array $error Error information retrieved from `error_get_last()`. | |
* @var true|WP_Error $handled Whether Recovery Mode handled the fatal error. | |
*/ | |
if ( ! defined( 'WP_CLI' ) && empty( $_REQUEST['skcdebug'] ) ) { | |
// Public requests will not display the PHP error details. | |
$this->display_default_error_template( $error, $handled ); | |
} else { | |
echo '<h1>Site PHP Error</h1>'; | |
var_dump( $error['type'] ); | |
echo '<pre>'; | |
echo $error['message'] . "\n"; | |
var_dump( $error['file'] ); | |
var_dump( $error['line'] ); | |
var_dump( $handled ); | |
var_dump( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) ); | |
echo '</pre>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment