File Editor
Directories:
.. (Back)
ID3
IXR
PHPMailer
Requests
SimplePie
Text
assets
block-bindings
block-patterns
block-supports
blocks
certificates
css
customize
fonts
html-api
images
interactivity-api
js
l10n
php-compat
pomo
rest-api
sitemaps
sodium_compat
style-engine
theme-compat
widgets
Files:
admin-bar.php
atomlib.php
author-template.php
block-bindings.php
block-editor.php
block-patterns.php
block-template-utils.php
block-template.php
blocks.php
bookmark-template.php
bookmark.php
cache-compat.php
cache.php
canonical.php
capabilities.php
category-template.php
category.php
class-IXR.php
class-avif-info.php
class-feed.php
class-http.php
class-json.php
class-oembed.php
class-phpass.php
class-phpmailer.php
class-pop3.php
class-requests.php
class-simplepie.php
class-smtp.php
class-snoopy.php
class-walker-category-dropdown.php
class-walker-category.php
class-walker-comment.php
class-walker-nav-menu.php
class-walker-page-dropdown.php
class-walker-page.php
class-wp-admin-bar.php
class-wp-ajax-response.php
class-wp-application-passwords.php
class-wp-block-bindings-registry.php
class-wp-block-bindings-source.php
class-wp-block-editor-context.php
class-wp-block-list.php
class-wp-block-parser-block.php
class-wp-block-parser-frame.php
class-wp-block-parser.php
class-wp-block-pattern-categories-registry.php
class-wp-block-patterns-registry.php
class-wp-block-styles-registry.php
class-wp-block-supports.php
class-wp-block-template.php
class-wp-block-type-registry.php
class-wp-block-type.php
class-wp-block.php
class-wp-classic-to-block-menu-converter.php
class-wp-comment-query.php
class-wp-comment.php
class-wp-customize-control.php
class-wp-customize-manager.php
class-wp-customize-nav-menus.php
class-wp-customize-panel.php
class-wp-customize-section.php
class-wp-customize-setting.php
class-wp-customize-widgets.php
class-wp-date-query.php
class-wp-dependencies.php
class-wp-dependency.php
class-wp-duotone.php
class-wp-editor.php
class-wp-embed.php
class-wp-error.php
class-wp-fatal-error-handler.php
class-wp-feed-cache-transient.php
class-wp-feed-cache.php
class-wp-hook.php
class-wp-http-cookie.php
class-wp-http-curl.php
class-wp-http-encoding.php
class-wp-http-ixr-client.php
class-wp-http-proxy.php
class-wp-http-requests-hooks.php
class-wp-http-requests-response.php
class-wp-http-response.php
class-wp-http-streams.php
class-wp-http.php
class-wp-image-editor-gd.php
class-wp-image-editor-imagick.php
class-wp-image-editor.php
class-wp-list-util.php
class-wp-locale-switcher.php
class-wp-locale.php
class-wp-matchesmapregex.php
class-wp-meta-query.php
class-wp-metadata-lazyloader.php
class-wp-navigation-fallback.php
class-wp-network-query.php
class-wp-network.php
class-wp-object-cache.php
class-wp-oembed-controller.php
class-wp-oembed.php
class-wp-paused-extensions-storage.php
class-wp-plugin-dependencies.php
class-wp-post-type.php
class-wp-post.php
class-wp-query.php
class-wp-recovery-mode-cookie-service.php
class-wp-recovery-mode-email-service.php
class-wp-recovery-mode-key-service.php
class-wp-recovery-mode-link-service.php
class-wp-recovery-mode.php
class-wp-rewrite.php
class-wp-role.php
class-wp-roles.php
class-wp-script-modules.php
class-wp-scripts.php
class-wp-session-tokens.php
class-wp-simplepie-file.php
class-wp-simplepie-sanitize-kses.php
class-wp-site-query.php
class-wp-site.php
class-wp-styles.php
class-wp-tax-query.php
class-wp-taxonomy.php
class-wp-term-query.php
class-wp-term.php
class-wp-text-diff-renderer-inline.php
class-wp-text-diff-renderer-table.php
class-wp-textdomain-registry.php
class-wp-theme-json-data.php
class-wp-theme-json-resolver.php
class-wp-theme-json-schema.php
class-wp-theme-json.php
class-wp-theme.php
class-wp-user-meta-session-tokens.php
class-wp-user-query.php
class-wp-user-request.php
class-wp-user.php
class-wp-walker.php
class-wp-widget-factory.php
class-wp-widget.php
class-wp-xmlrpc-server.php
class-wp.php
class-wpdb.php
class.wp-dependencies.php
class.wp-scripts.php
class.wp-styles.php
comment-template.php
comment.php
compat.php
cron.php
date.php
default-constants.php
default-filters.php
default-widgets.php
deprecated.php
embed-template.php
embed.php
error-protection.php
feed-atom-comments.php
feed-atom.php
feed-rdf.php
feed-rss.php
feed-rss2-comments.php
feed-rss2.php
feed.php
fonts.php
formatting.php
functions.php
functions.wp-scripts.php
functions.wp-styles.php
general-template.php
global-styles-and-settings.php
http.php
https-detection.php
https-migration.php
kses.php
l10n.php
link-template.php
load.php
locale.php
media-template.php
media.php
meta.php
ms-blogs.php
ms-default-constants.php
ms-default-filters.php
ms-deprecated.php
ms-files.php
ms-functions.php
ms-load.php
ms-network.php
ms-settings.php
ms-site.php
nav-menu-template.php
nav-menu.php
option.php
pluggable-deprecated.php
pluggable.php
plugin.php
post-formats.php
post-template.php
post-thumbnail-template.php
post.php
query.php
registration-functions.php
registration.php
rest-api.php
revision.php
rewrite.php
robots-template.php
rss-functions.php
rss.php
script-loader.php
script-modules.php
session.php
shortcodes.php
sitemaps.php
spl-autoload-compat.php
style-engine.php
taxonomy.php
template-canvas.php
template-loader.php
template.php
theme-previews.php
theme-templates.php
theme.php
update.php
user.php
vars.php
version.php
widgets.php
wp-db.php
wp-diff.php
Create New File
Create
Edit File: class-wp-fatal-error-handler.php
<?php /** * Error Protection API: WP_Fatal_Error_Handler class * * @package WordPress * @since 5.2.0 */ /** * Core class used as the default shutdown handler for fatal errors. * * A drop-in 'fatal-error-handler.php' can be used to override the instance of this class and use a custom * implementation for the fatal error handler that WordPress registers. The custom class should extend this class and * can override its methods individually as necessary. The file must return the instance of the class that should be * registered. * * @since 5.2.0 */ #[AllowDynamicProperties] class WP_Fatal_Error_Handler { /** * Runs the shutdown handler. * * This method is registered via `register_shutdown_function()`. * * @since 5.2.0 * * @global WP_Locale $wp_locale WordPress date and time locale object. */ public function handle() { if ( defined( 'WP_SANDBOX_SCRAPING' ) && WP_SANDBOX_SCRAPING ) { return; } // Do not trigger the fatal error handler while updates are being installed. if ( wp_is_maintenance_mode() ) { return; } try { // Bail if no error found. $error = $this->detect_error(); if ( ! $error ) { return; } if ( ! isset( $GLOBALS['wp_locale'] ) && function_exists( 'load_default_textdomain' ) ) { load_default_textdomain(); } $handled = false; if ( ! is_multisite() && wp_recovery_mode()->is_initialized() ) { $handled = wp_recovery_mode()->handle_error( $error ); } // Display the PHP error template if headers not sent. if ( is_admin() || ! headers_sent() ) { $this->display_error_template( $error, $handled ); } } catch ( Exception $e ) { // Catch exceptions and remain silent. } } /** * Detects the error causing the crash if it should be handled. * * @since 5.2.0 * * @return array|null Error information returned by `error_get_last()`, or null * if none was recorded or the error should not be handled. */ protected function detect_error() { $error = error_get_last(); // No error, just skip the error handling code. if ( null === $error ) { return null; } // Bail if this error should not be handled. if ( ! $this->should_handle_error( $error ) ) { return null; } return $error; } /** * Determines whether we are dealing with an error that WordPress should handle * in order to protect the admin backend against WSODs. * * @since 5.2.0 * * @param array $error Error information retrieved from `error_get_last()`. * @return bool Whether WordPress should handle this error. */ protected function should_handle_error( $error ) { $error_types_to_handle = array( E_ERROR, E_PARSE, E_USER_ERROR, E_COMPILE_ERROR, E_RECOVERABLE_ERROR, ); if ( isset( $error['type'] ) && in_array( $error['type'], $error_types_to_handle, true ) ) { return true; } /** * Filters whether a given thrown error should be handled by the fatal error handler. * * This filter is only fired if the error is not already configured to be handled by WordPress core. As such, * it exclusively allows adding further rules for which errors should be handled, but not removing existing * ones. * * @since 5.2.0 * * @param bool $should_handle_error Whether the error should be handled by the fatal error handler. * @param array $error Error information retrieved from `error_get_last()`. */ return (bool) apply_filters( 'wp_should_handle_php_error', false, $error ); } /** * Displays the PHP error template and sends the HTTP status code, typically 500. * * A drop-in 'php-error.php' can be used as a custom template. This drop-in should control the HTTP status code and * print the HTML markup indicating that a PHP error occurred. Note that this drop-in may potentially be executed * very early in the WordPress bootstrap process, so any core functions used that are not part of * `wp-includes/load.php` should be checked for before being called. * * If no such drop-in is available, this will call {@see WP_Fatal_Error_Handler::display_default_error_template()}. * * @since 5.2.0 * @since 5.3.0 The `$handled` parameter was added. * * @param array $error Error information retrieved from `error_get_last()`. * @param true|WP_Error $handled Whether Recovery Mode handled the fatal error. */ protected function display_error_template( $error, $handled ) { if ( defined( 'WP_CONTENT_DIR' ) ) { // Load custom PHP error template, if present. $php_error_pluggable = WP_CONTENT_DIR . '/php-error.php'; if ( is_readable( $php_error_pluggable ) ) { require_once $php_error_pluggable; return; } } // Otherwise, display the default error template. $this->display_default_error_template( $error, $handled ); } /** * Displays the default PHP error template. * * This method is called conditionally if no 'php-error.php' drop-in is available. * * It calls {@see wp_die()} with a message indicating that the site is experiencing technical difficulties and a * login link to the admin backend. The {@see 'wp_php_error_message'} and {@see 'wp_php_error_args'} filters can * be used to modify these parameters. * * @since 5.2.0 * @since 5.3.0 The `$handled` parameter was added. * * @param array $error Error information retrieved from `error_get_last()`. * @param true|WP_Error $handled Whether Recovery Mode handled the fatal error. */ protected function display_default_error_template( $error, $handled ) { if ( ! function_exists( '__' ) ) { wp_load_translations_early(); } if ( ! function_exists( 'wp_die' ) ) { require_once ABSPATH . WPINC . '/functions.php'; } if ( ! class_exists( 'WP_Error' ) ) { require_once ABSPATH . WPINC . '/class-wp-error.php'; } if ( true === $handled && wp_is_recovery_mode() ) { $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.' ); } elseif ( is_protected_endpoint() && wp_recovery_mode()->is_initialized() ) { if ( is_multisite() ) { $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.' ); } else { $message = __( 'There has been a critical error on this website. Please check your site admin email inbox for instructions.' ); } } else { $message = __( 'There has been a critical error on this website.' ); } $message = sprintf( '<p>%s</p><p><a href="%s">%s</a></p>', $message, /* translators: Documentation about troubleshooting. */ __( 'https://wordpress.org/documentation/article/faq-troubleshooting/' ), __( 'Learn more about troubleshooting WordPress.' ) ); $args = array( 'response' => 500, 'exit' => false, ); /** * Filters the message that the default PHP error template displays. * * @since 5.2.0 * * @param string $message HTML error message to display. * @param array $error Error information retrieved from `error_get_last()`. */ $message = apply_filters( 'wp_php_error_message', $message, $error ); /** * Filters the arguments passed to {@see wp_die()} for the default PHP error template. * * @since 5.2.0 * * @param array $args Associative array of arguments passed to `wp_die()`. By default these contain a * 'response' key, and optionally 'link_url' and 'link_text' keys. * @param array $error Error information retrieved from `error_get_last()`. */ $args = apply_filters( 'wp_php_error_args', $args, $error ); $wp_error = new WP_Error( 'internal_server_error', $message, array( 'error' => $error, ) ); wp_die( $wp_error, '', $args ); } }
Save Changes
Rename File
Rename