From b324c419ec77056aca1a21604b75d041dd4e9990 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 27 Mar 2019 00:15:23 +0000 Subject: [PATCH] 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 --- .../class-wp-fatal-error-handler.php | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wp-fatal-error-handler.php b/src/wp-includes/class-wp-fatal-error-handler.php index e469497af3..fa189cc57d 100644 --- a/src/wp-includes/class-wp-fatal-error-handler.php +++ b/src/wp-includes/class-wp-fatal-error-handler.php @@ -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 ); } }