WP_Fatal_Error_Handler::should_handle_error() WordPress Method

The WP_Fatal_Error_Handler::should_handle_error() method is used to determine if a fatal error should be handled by the error handler. This is useful for situations where you want to allow WordPress to handle some errors but not others. For example, you might want to handle errors that occur during a plugin update but not during a normal request.

WP_Fatal_Error_Handler::should_handle_error( array $error ) #

Determines whether we are dealing with an error that WordPress should handle in order to protect the admin backend against WSODs.


Parameters

$error

(array)(Required)Error information retrieved from error_get_last().


Top ↑

Return

(bool) Whether WordPress should handle this error.


Top ↑

Source

File: wp-includes/class-wp-fatal-error-handler.php

	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 );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.