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
This commit is contained in:
Felix Arntz 2019-01-21 19:10:52 +00:00
parent e992ae3ea2
commit 6645578424
3 changed files with 42 additions and 13 deletions

View File

@ -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.' );

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' => '',

View File

@ -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.