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.
Built from https://develop.svn.wordpress.org/trunk@45023


git-svn-id: http://core.svn.wordpress.org/trunk@44832 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-03-27 00:16:51 +00:00
parent b4ded564ff
commit 455dccbc00
2 changed files with 17 additions and 9 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 );
}
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.2-alpha-45022';
$wp_version = '5.2-alpha-45023';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.