Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-inclu...
File: class-wp-fatal-error-handler.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Error Protection API: WP_Fatal_Error_Handler class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 5.2.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Core class used as the default shutdown handler for fatal errors.
[9] Fix | Delete
*
[10] Fix | Delete
* A drop-in 'fatal-error-handler.php' can be used to override the instance of this class and use a custom
[11] Fix | Delete
* implementation for the fatal error handler that WordPress registers. The custom class should extend this class and
[12] Fix | Delete
* can override its methods individually as necessary. The file must return the instance of the class that should be
[13] Fix | Delete
* registered.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 5.2.0
[16] Fix | Delete
*/
[17] Fix | Delete
#[AllowDynamicProperties]
[18] Fix | Delete
class WP_Fatal_Error_Handler {
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Runs the shutdown handler.
[22] Fix | Delete
*
[23] Fix | Delete
* This method is registered via `register_shutdown_function()`.
[24] Fix | Delete
*
[25] Fix | Delete
* @since 5.2.0
[26] Fix | Delete
*
[27] Fix | Delete
* @global WP_Locale $wp_locale WordPress date and time locale object.
[28] Fix | Delete
*/
[29] Fix | Delete
public function handle() {
[30] Fix | Delete
if ( defined( 'WP_SANDBOX_SCRAPING' ) && WP_SANDBOX_SCRAPING ) {
[31] Fix | Delete
return;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
// Do not trigger the fatal error handler while updates are being installed.
[35] Fix | Delete
if ( wp_is_maintenance_mode() ) {
[36] Fix | Delete
return;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
try {
[40] Fix | Delete
// Bail if no error found.
[41] Fix | Delete
$error = $this->detect_error();
[42] Fix | Delete
if ( ! $error ) {
[43] Fix | Delete
return;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
if ( ! isset( $GLOBALS['wp_locale'] ) && function_exists( 'load_default_textdomain' ) ) {
[47] Fix | Delete
load_default_textdomain();
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$handled = false;
[51] Fix | Delete
[52] Fix | Delete
if ( ! is_multisite() && wp_recovery_mode()->is_initialized() ) {
[53] Fix | Delete
$handled = wp_recovery_mode()->handle_error( $error );
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
// Display the PHP error template if headers not sent.
[57] Fix | Delete
if ( is_admin() || ! headers_sent() ) {
[58] Fix | Delete
$this->display_error_template( $error, $handled );
[59] Fix | Delete
}
[60] Fix | Delete
} catch ( Exception $e ) {
[61] Fix | Delete
// Catch exceptions and remain silent.
[62] Fix | Delete
}
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* Detects the error causing the crash if it should be handled.
[67] Fix | Delete
*
[68] Fix | Delete
* @since 5.2.0
[69] Fix | Delete
*
[70] Fix | Delete
* @return array|null Error information returned by `error_get_last()`, or null
[71] Fix | Delete
* if none was recorded or the error should not be handled.
[72] Fix | Delete
*/
[73] Fix | Delete
protected function detect_error() {
[74] Fix | Delete
$error = error_get_last();
[75] Fix | Delete
[76] Fix | Delete
// No error, just skip the error handling code.
[77] Fix | Delete
if ( null === $error ) {
[78] Fix | Delete
return null;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
// Bail if this error should not be handled.
[82] Fix | Delete
if ( ! $this->should_handle_error( $error ) ) {
[83] Fix | Delete
return null;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
return $error;
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Determines whether we are dealing with an error that WordPress should handle
[91] Fix | Delete
* in order to protect the admin backend against WSODs.
[92] Fix | Delete
*
[93] Fix | Delete
* @since 5.2.0
[94] Fix | Delete
*
[95] Fix | Delete
* @param array $error Error information retrieved from `error_get_last()`.
[96] Fix | Delete
* @return bool Whether WordPress should handle this error.
[97] Fix | Delete
*/
[98] Fix | Delete
protected function should_handle_error( $error ) {
[99] Fix | Delete
$error_types_to_handle = array(
[100] Fix | Delete
E_ERROR,
[101] Fix | Delete
E_PARSE,
[102] Fix | Delete
E_USER_ERROR,
[103] Fix | Delete
E_COMPILE_ERROR,
[104] Fix | Delete
E_RECOVERABLE_ERROR,
[105] Fix | Delete
);
[106] Fix | Delete
[107] Fix | Delete
if ( isset( $error['type'] ) && in_array( $error['type'], $error_types_to_handle, true ) ) {
[108] Fix | Delete
return true;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Filters whether a given thrown error should be handled by the fatal error handler.
[113] Fix | Delete
*
[114] Fix | Delete
* This filter is only fired if the error is not already configured to be handled by WordPress core. As such,
[115] Fix | Delete
* it exclusively allows adding further rules for which errors should be handled, but not removing existing
[116] Fix | Delete
* ones.
[117] Fix | Delete
*
[118] Fix | Delete
* @since 5.2.0
[119] Fix | Delete
*
[120] Fix | Delete
* @param bool $should_handle_error Whether the error should be handled by the fatal error handler.
[121] Fix | Delete
* @param array $error Error information retrieved from `error_get_last()`.
[122] Fix | Delete
*/
[123] Fix | Delete
return (bool) apply_filters( 'wp_should_handle_php_error', false, $error );
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Displays the PHP error template and sends the HTTP status code, typically 500.
[128] Fix | Delete
*
[129] Fix | Delete
* A drop-in 'php-error.php' can be used as a custom template. This drop-in should control the HTTP status code and
[130] Fix | Delete
* print the HTML markup indicating that a PHP error occurred. Note that this drop-in may potentially be executed
[131] Fix | Delete
* very early in the WordPress bootstrap process, so any core functions used that are not part of
[132] Fix | Delete
* `wp-includes/load.php` should be checked for before being called.
[133] Fix | Delete
*
[134] Fix | Delete
* If no such drop-in is available, this will call {@see WP_Fatal_Error_Handler::display_default_error_template()}.
[135] Fix | Delete
*
[136] Fix | Delete
* @since 5.2.0
[137] Fix | Delete
* @since 5.3.0 The `$handled` parameter was added.
[138] Fix | Delete
*
[139] Fix | Delete
* @param array $error Error information retrieved from `error_get_last()`.
[140] Fix | Delete
* @param true|WP_Error $handled Whether Recovery Mode handled the fatal error.
[141] Fix | Delete
*/
[142] Fix | Delete
protected function display_error_template( $error, $handled ) {
[143] Fix | Delete
if ( defined( 'WP_CONTENT_DIR' ) ) {
[144] Fix | Delete
// Load custom PHP error template, if present.
[145] Fix | Delete
$php_error_pluggable = WP_CONTENT_DIR . '/php-error.php';
[146] Fix | Delete
if ( is_readable( $php_error_pluggable ) ) {
[147] Fix | Delete
require_once $php_error_pluggable;
[148] Fix | Delete
[149] Fix | Delete
return;
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
// Otherwise, display the default error template.
[154] Fix | Delete
$this->display_default_error_template( $error, $handled );
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Displays the default PHP error template.
[159] Fix | Delete
*
[160] Fix | Delete
* This method is called conditionally if no 'php-error.php' drop-in is available.
[161] Fix | Delete
*
[162] Fix | Delete
* It calls {@see wp_die()} with a message indicating that the site is experiencing technical difficulties and a
[163] Fix | Delete
* login link to the admin backend. The {@see 'wp_php_error_message'} and {@see 'wp_php_error_args'} filters can
[164] Fix | Delete
* be used to modify these parameters.
[165] Fix | Delete
*
[166] Fix | Delete
* @since 5.2.0
[167] Fix | Delete
* @since 5.3.0 The `$handled` parameter was added.
[168] Fix | Delete
*
[169] Fix | Delete
* @param array $error Error information retrieved from `error_get_last()`.
[170] Fix | Delete
* @param true|WP_Error $handled Whether Recovery Mode handled the fatal error.
[171] Fix | Delete
*/
[172] Fix | Delete
protected function display_default_error_template( $error, $handled ) {
[173] Fix | Delete
if ( ! function_exists( '__' ) ) {
[174] Fix | Delete
wp_load_translations_early();
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
if ( ! function_exists( 'wp_die' ) ) {
[178] Fix | Delete
require_once ABSPATH . WPINC . '/functions.php';
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
if ( ! class_exists( 'WP_Error' ) ) {
[182] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-error.php';
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
if ( true === $handled && wp_is_recovery_mode() ) {
[186] Fix | Delete
$message = __( 'There has been a critical error on this website, putting it in recovery mode. Please check the Themes and Plugins screens for more details. If you just installed or updated a theme or plugin, check the relevant page for that first.' );
[187] Fix | Delete
} elseif ( is_protected_endpoint() && wp_recovery_mode()->is_initialized() ) {
[188] Fix | Delete
if ( is_multisite() ) {
[189] Fix | Delete
$message = __( 'There has been a critical error on this website. Please reach out to your site administrator, and inform them of this error for further assistance.' );
[190] Fix | Delete
} else {
[191] Fix | Delete
$message = __( 'There has been a critical error on this website. Please check your site admin email inbox for instructions.' );
[192] Fix | Delete
}
[193] Fix | Delete
} else {
[194] Fix | Delete
$message = __( 'There has been a critical error on this website.' );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
$message = sprintf(
[198] Fix | Delete
'<p>%s</p><p><a href="%s">%s</a></p>',
[199] Fix | Delete
$message,
[200] Fix | Delete
/* translators: Documentation about troubleshooting. */
[201] Fix | Delete
__( 'https://wordpress.org/documentation/article/faq-troubleshooting/' ),
[202] Fix | Delete
__( 'Learn more about troubleshooting WordPress.' )
[203] Fix | Delete
);
[204] Fix | Delete
[205] Fix | Delete
$args = array(
[206] Fix | Delete
'response' => 500,
[207] Fix | Delete
'exit' => false,
[208] Fix | Delete
);
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Filters the message that the default PHP error template displays.
[212] Fix | Delete
*
[213] Fix | Delete
* @since 5.2.0
[214] Fix | Delete
*
[215] Fix | Delete
* @param string $message HTML error message to display.
[216] Fix | Delete
* @param array $error Error information retrieved from `error_get_last()`.
[217] Fix | Delete
*/
[218] Fix | Delete
$message = apply_filters( 'wp_php_error_message', $message, $error );
[219] Fix | Delete
[220] Fix | Delete
/**
[221] Fix | Delete
* Filters the arguments passed to {@see wp_die()} for the default PHP error template.
[222] Fix | Delete
*
[223] Fix | Delete
* @since 5.2.0
[224] Fix | Delete
*
[225] Fix | Delete
* @param array $args Associative array of arguments passed to `wp_die()`. By default these contain a
[226] Fix | Delete
* 'response' key, and optionally 'link_url' and 'link_text' keys.
[227] Fix | Delete
* @param array $error Error information retrieved from `error_get_last()`.
[228] Fix | Delete
*/
[229] Fix | Delete
$args = apply_filters( 'wp_php_error_args', $args, $error );
[230] Fix | Delete
[231] Fix | Delete
$wp_error = new WP_Error(
[232] Fix | Delete
'internal_server_error',
[233] Fix | Delete
$message,
[234] Fix | Delete
array(
[235] Fix | Delete
'error' => $error,
[236] Fix | Delete
)
[237] Fix | Delete
);
[238] Fix | Delete
[239] Fix | Delete
wp_die( $wp_error, '', $args );
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function