Bootstrap/Load: In fatal error handler, pass the error information through to error template and associated filters: `wp_php_error_message`, `wp_php_error_args`.

This allows the custom error handler and default error message filters to inspect the error and perform logic based on its properties.

Props johnbillion.
Fixes #46620.

git-svn-id: https://develop.svn.wordpress.org/trunk@45023 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-03-27 00:15:23 +00:00
parent dd7caf0fd3
commit b324c419ec
1 changed files with 16 additions and 8 deletions

View File

@ -39,7 +39,7 @@ class WP_Fatal_Error_Handler {
// Display the PHP error template if headers not sent.
if ( ! headers_sent() ) {
$this->display_error_template();
$this->display_error_template( $error );
}
} catch ( Exception $e ) {
// Catch exceptions and remain silent.
@ -117,8 +117,10 @@ class WP_Fatal_Error_Handler {
* If no such drop-in is available, this will call {@see WP_Fatal_Error_Handler::display_default_error_template()}.
*
* @since 5.2.0
*
* @param array $error Error information retrieved from `error_get_last()`.
*/
protected function display_error_template() {
protected function display_error_template( $error ) {
if ( defined( 'WP_CONTENT_DIR' ) ) {
// Load custom PHP error template, if present.
$php_error_pluggable = WP_CONTENT_DIR . '/php-error.php';
@ -130,7 +132,7 @@ class WP_Fatal_Error_Handler {
}
// Otherwise, display the default error template.
$this->display_default_error_template();
$this->display_default_error_template( $error );
}
/**
@ -143,8 +145,10 @@ class WP_Fatal_Error_Handler {
* be used to modify these parameters.
*
* @since 5.2.0
*
* @param array $error Error information retrieved from `error_get_last()`.
*/
protected function display_default_error_template() {
protected function display_default_error_template( $error ) {
if ( ! function_exists( '__' ) ) {
wp_load_translations_early();
}
@ -166,8 +170,9 @@ class WP_Fatal_Error_Handler {
* @since 5.2.0
*
* @param string $message HTML error message to display.
* @param array $error Error information retrieved from `error_get_last()`.
*/
$message = apply_filters( 'wp_php_error_message', $message );
$message = apply_filters( 'wp_php_error_message', $message, $error );
/**
* Filters the arguments passed to {@see wp_die()} for the default PHP error template.
@ -176,11 +181,14 @@ class WP_Fatal_Error_Handler {
*
* @param array $args Associative array of arguments passed to `wp_die()`. By default these contain a
* 'response' key, and optionally 'link_url' and 'link_text' keys.
* @param array $error Error information retrieved from `error_get_last()`.
*/
$args = apply_filters( 'wp_php_error_args', $args );
$args = apply_filters( 'wp_php_error_args', $args, $error );
$error = new WP_Error( 'internal_server_error', $message );
$wp_error = new WP_Error( 'internal_server_error', $message, array(
'error' => $error,
) );
wp_die( $error, '', $args );
wp_die( $wp_error, '', $args );
}
}