函数文档

wp_is_fatal_error_handler_enabled()

💡 云策文档标注

概述

wp_is_fatal_error_handler_enabled() 函数用于检查 WordPress 的致命错误处理器是否启用。它通过检查常量 WP_DISABLE_FATAL_ERROR_HANDLER 或应用过滤器 'wp_fatal_error_handler_enabled' 来确定状态。

关键要点

  • 函数返回布尔值:true 表示致命错误处理器启用,false 表示禁用。
  • 可通过在 wp-config.php 中定义常量 WP_DISABLE_FATAL_ERROR_HANDLER 来禁用处理器。
  • 过滤器 'wp_fatal_error_handler_enabled' 可用于修改返回值,但需注意其运行时机,通常需在 WordPress 加载前定义 $wp_filter 全局变量。

代码示例

function wp_is_fatal_error_handler_enabled() {
    $enabled = ! defined( 'WP_DISABLE_FATAL_ERROR_HANDLER' ) || ! WP_DISABLE_FATAL_ERROR_HANDLER;
    return apply_filters( 'wp_fatal_error_handler_enabled', $enabled );
}

注意事项

过滤器 'wp_fatal_error_handler_enabled' 在插件可用之前运行,因此不能由插件、mu-plugins 或主题直接使用。如需使用,必须在 WordPress 加载前(通常在 wp-config.php 中)定义 $wp_filter 全局变量。


📄 原文内容

Checks whether the fatal error handler is enabled.

Description

A constant WP_DISABLE_FATAL_ERROR_HANDLER can be set in wp-config.php to disable it, or alternatively the ‘wp_fatal_error_handler_enabled’ filter can be used to modify the return value.

Return

bool True if the fatal error handler is enabled, false otherwise.

Source

function wp_is_fatal_error_handler_enabled() {
	$enabled = ! defined( 'WP_DISABLE_FATAL_ERROR_HANDLER' ) || ! WP_DISABLE_FATAL_ERROR_HANDLER;

	/**
	 * Filters whether the fatal error handler is enabled.
	 *
	 * **Important:** This filter runs before it can be used by plugins. It cannot
	 * be used by plugins, mu-plugins, or themes. To use this filter you must define
	 * a `$wp_filter` global before WordPress loads, usually in `wp-config.php`.
	 *
	 * Example:
	 *
	 *     $GLOBALS['wp_filter'] = array(
	 *         'wp_fatal_error_handler_enabled' => array(
	 *             10 => array(
	 *                 array(
	 *                     'accepted_args' => 0,
	 *                     'function'      => function() {
	 *                         return false;
	 *                     },
	 *                 ),
	 *             ),
	 *         ),
	 *     );
	 *
	 * Alternatively you can use the `WP_DISABLE_FATAL_ERROR_HANDLER` constant.
	 *
	 * @since 5.2.0
	 *
	 * @param bool $enabled True if the fatal error handler is enabled, false otherwise.
	 */
	return apply_filters( 'wp_fatal_error_handler_enabled', $enabled );
}

Hooks

apply_filters( ‘wp_fatal_error_handler_enabled’, bool $enabled )

Filters whether the fatal error handler is enabled.

Changelog

Version Description
5.2.0 Introduced.