Make WordPress Core

Changeset 45023


Ignore:
Timestamp:
03/27/2019 12:15:23 AM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-fatal-error-handler.php

    r45014 r45023  
    4040            // Display the PHP error template if headers not sent.
    4141            if ( ! headers_sent() ) {
    42                 $this->display_error_template();
     42                $this->display_error_template( $error );
    4343            }
    4444        } catch ( Exception $e ) {
     
    118118     *
    119119     * @since 5.2.0
     120     *
     121     * @param array $error Error information retrieved from `error_get_last()`.
    120122     */
    121     protected function display_error_template() {
     123    protected function display_error_template( $error ) {
    122124        if ( defined( 'WP_CONTENT_DIR' ) ) {
    123125            // Load custom PHP error template, if present.
     
    131133
    132134        // Otherwise, display the default error template.
    133         $this->display_default_error_template();
     135        $this->display_default_error_template( $error );
    134136    }
    135137
     
    144146     *
    145147     * @since 5.2.0
     148     *
     149     * @param array $error Error information retrieved from `error_get_last()`.
    146150     */
    147     protected function display_default_error_template() {
     151    protected function display_default_error_template( $error ) {
    148152        if ( ! function_exists( '__' ) ) {
    149153            wp_load_translations_early();
     
    167171         *
    168172         * @param string $message HTML error message to display.
     173         * @param array  $error   Error information retrieved from `error_get_last()`.
    169174         */
    170         $message = apply_filters( 'wp_php_error_message', $message );
     175        $message = apply_filters( 'wp_php_error_message', $message, $error );
    171176
    172177        /**
     
    177182         * @param array $args Associative array of arguments passed to `wp_die()`. By default these contain a
    178183         *                    'response' key, and optionally 'link_url' and 'link_text' keys.
     184         * @param array $error Error information retrieved from `error_get_last()`.
    179185         */
    180         $args = apply_filters( 'wp_php_error_args', $args );
     186        $args = apply_filters( 'wp_php_error_args', $args, $error );
    181187
    182         $error = new WP_Error( 'internal_server_error', $message );
     188        $wp_error = new WP_Error( 'internal_server_error', $message, array(
     189            'error' => $error,
     190        ) );
    183191
    184         wp_die( $error, '', $args );
     192        wp_die( $wp_error, '', $args );
    185193    }
    186194}
Note: See TracChangeset for help on using the changeset viewer.