wp_fatal_error_handler_enabled
云策文档标注
概述
wp_fatal_error_handler_enabled 是一个 WordPress 过滤器,用于控制致命错误处理器的启用状态。它运行在插件加载之前,因此无法被插件、MU 插件或主题直接使用,通常需要在 wp-config.php 中通过全局变量或常量进行配置。
关键要点
- 这是一个过滤器,用于决定是否启用 WordPress 的致命错误处理器。
- 过滤器在插件加载前运行,因此不能通过常规插件或主题代码添加钩子。
- 使用方式:在 wp-config.php 中定义 $wp_filter 全局变量或使用 WP_DISABLE_FATAL_ERROR_HANDLER 常量。
- 相关函数:wp_is_fatal_error_handler_enabled() 用于检查处理器是否启用。
- 引入版本:WordPress 5.2.0。
代码示例
$GLOBALS['wp_filter'] = array(
'wp_fatal_error_handler_enabled' => array(
10 => array(
array(
'accepted_args' => 0,
'function' => function() {
return false;
},
),
),
),
);注意事项
由于过滤器运行时机较早,开发者需注意配置方式,避免在插件或主题中直接使用 add_filter(),否则可能无效。
原文内容
Filters whether the fatal error handler is enabled.
Description
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.
Parameters
$enabledbool-
True if the fatal error handler is enabled, false otherwise.
Source
return apply_filters( 'wp_fatal_error_handler_enabled', $enabled );
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |