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.


git-svn-id: https://develop.svn.wordpress.org/trunk@44671 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Felix Arntz
2019-01-21 19:09:23 +00:00
parent 8fe01c0621
commit 50d4abc949
2 changed files with 41 additions and 12 deletions

View File

@@ -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() ) {
</body>
</html>
<?php
die();
if ( $r['exit'] ) {
die();
}
}
/**
@@ -3236,7 +3239,9 @@ function _json_wp_die_handler( $message, $title = '', $args = array() ) {
}
echo wp_json_encode( $data );
die();
if ( $r['exit'] ) {
die();
}
}
/**
@@ -3262,7 +3267,9 @@ function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
$error = new IXR_Error( $r['response'], $message );
$wp_xmlrpc_server->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' => '',