Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3886,6 +3886,20 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) {
$message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>";
}

// Ensure HTTP 500 status code for critical errors, even if headers were already sent.
$is_critical_error = false;
if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function_exists check necessary? It's defined in load.php, which is loaded before this file.

References:

require ABSPATH . WPINC . '/load.php';

require ABSPATH . WPINC . '/functions.php';

$error_code = $message->get_error_code();
$is_critical_error = ( 'internal_server_error' === $error_code );
} elseif ( 'internal_server_error' === $parsed_args['code'] || 500 === $parsed_args['response'] ) {
$is_critical_error = true;
}

if ( $is_critical_error ) {
$parsed_args['response'] = 500;
http_response_code( 500 );
}

if ( ! did_action( 'admin_head' ) ) :
if ( ! headers_sent() ) {
header( "Content-Type: text/html; charset={$parsed_args['charset']}" );
Expand Down
Loading