From 6645578424cac76046102513537bcd313b8e5655 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Mon, 21 Jan 2019 19:10:52 +0000 Subject: [PATCH] Bootstrap/Load: Ensure that the fatal error shutdown handler does not prevent other shutdown handlers from being called. This changeset adds support for a new `wp_die()` argument `exit`, which defaults to true and determines whether `wp_die()` should actually terminate the request. The new fatal error handler then calls `wp_die()` with that argument set to false, as calling `die()` or `exit` from a PHP shutdown function prevents other shutdown functions from being called. Props schlessera, johnbillion. Fixes #46038. See #44458. Built from https://develop.svn.wordpress.org/trunk@44671 git-svn-id: http://core.svn.wordpress.org/trunk@44502 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-shutdown-handler.php | 7 +++- wp-includes/functions.php | 46 ++++++++++++++++++----- wp-includes/version.php | 2 +- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/wp-includes/class-wp-shutdown-handler.php b/wp-includes/class-wp-shutdown-handler.php index c55901dd4a..18eee6a2a4 100644 --- a/wp-includes/class-wp-shutdown-handler.php +++ b/wp-includes/class-wp-shutdown-handler.php @@ -136,7 +136,7 @@ class WP_Shutdown_Handler { $php_error_pluggable = WP_CONTENT_DIR . '/php-error.php'; if ( is_readable( $php_error_pluggable ) ) { require_once $php_error_pluggable; - die(); + return; } } @@ -166,7 +166,10 @@ class WP_Shutdown_Handler { $message = __( 'The site is experiencing technical difficulties.' ); - $args = array( 'response' => 500 ); + $args = array( + 'response' => 500, + 'exit' => false, + ); if ( function_exists( 'admin_url' ) ) { $args['link_url'] = admin_url(); $args['link_text'] = __( 'Log into the admin backend to fix this.' ); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 00ebbe9c62..400161d8e7 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2957,6 +2957,7 @@ function wp_nonce_ays( $action ) { * Default is the value of is_rtl(). * @type string $code Error code to use. Default is 'wp_die', or the main error code if $message * is a WP_Error. + * @type bool $exit Whether to exit the process after completion. Default true. * } */ function wp_die( $message = '', $title = '', $args = array() ) { @@ -3201,7 +3202,9 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) { output( $error->getXml() ); } - die(); + if ( $r['exit'] ) { + die(); + } } /** @@ -3291,9 +3298,16 @@ function _ajax_wp_die_handler( $message, $title = '', $args = array() ) { } if ( is_scalar( $message ) ) { - die( (string) $message ); + $message = (string) $message; + } else { + $message = '0'; } - die( '0' ); + + if ( $r['exit'] ) { + die( $message ); + } + + echo $message; } /** @@ -3302,15 +3316,26 @@ function _ajax_wp_die_handler( $message, $title = '', $args = array() ) { * This is the handler for wp_die when processing APP requests. * * @since 3.4.0 + * @since 5.1.0 Added the $title and $args parameters. * @access private * - * @param string $message Optional. Response to print. Default empty. + * @param string $message Optional. Response to print. Default empty. + * @param string $title Optional. Error title (unused). Default empty. + * @param string|array $args Optional. Arguments to control behavior. Default empty array. */ -function _scalar_wp_die_handler( $message = '' ) { - if ( is_scalar( $message ) ) { - die( (string) $message ); +function _scalar_wp_die_handler( $message = '', $title = '', $args = array() ) { + list( $message, $title, $r ) = _wp_die_process_input( $message, $title, $args ); + + if ( $r['exit'] ) { + if ( is_scalar( $message ) ) { + die( (string) $message ); + } + die(); + } + + if ( is_scalar( $message ) ) { + echo (string) $message; } - die(); } /** @@ -3328,6 +3353,7 @@ function _wp_die_process_input( $message, $title = '', $args = array() ) { $defaults = array( 'response' => 0, 'code' => '', + 'exit' => true, 'back_link' => false, 'link_url' => '', 'link_text' => '', diff --git a/wp-includes/version.php b/wp-includes/version.php index 625bb0c6f3..419fb4b0de 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-beta1-44670'; +$wp_version = '5.1-beta1-44671'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.