wppaste
WordPress

WP_Fatal_Error_Handler

Since
5.2.0
Source
wp-includes/class-wp-fatal-error-handler.php:19
Core class used as the default shutdown handler for fatal errors.

Description

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.

Compatibility

WordPress
since 5.2.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 3

Every hook that fires from inside WP_Fatal_Error_Handler, in the order it appears in the class, grouped by the method that fires it.

Methods · 5

Source code

#[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.

Changelog

Introduced in 5.2.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/class-wp-fatal-error-handler.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.