钩子文档

enable_wp_debug_mode_checks

💡 云策文档标注

概述

enable_wp_debug_mode_checks 是一个 WordPress 过滤器,用于控制是否执行 WP_DEBUG 及相关常量的检查。它主要面向非 Web 运行时环境,允许开发者自定义调试模式的行为。

关键要点

  • 过滤器名称:enable_wp_debug_mode_checks
  • 作用:允许或禁止调试模式检查,返回 false 时跳过 WP_DEBUG 检查,使用 PHP 默认错误值
  • 使用场景:非 Web 运行时,需在 WordPress 加载前定义 $wp_filter 全局变量,通常在 wp-config.php 中配置
  • 参数:$enable_debug_mode,布尔值,默认为 true
  • 引入版本:4.6.0

代码示例

$GLOBALS['wp_filter'] = array(
    'enable_wp_debug_mode_checks' => array(
        10 => array(
            array(
                'accepted_args' => 0,
                'function'      => function() {
                    return false;
                },
            ),
        ),
    ),
);

注意事项

  • 使用此过滤器需在 WordPress 加载前定义 $wp_filter 全局变量,否则可能无法生效
  • 返回 false 后,需自行处理错误报告设置,否则将使用 PHP 默认值
  • 相关函数:wp_debug_mode(),位于 wp-includes/load.php

📄 原文内容

Filters whether to allow the debug mode check to occur.

Description

This filter runs before it can be used by plugins. It is designed for non-web runtimes. Returning false causes the WP_DEBUG and related constants to not be checked and the default PHP values for errors will be used unless you take care to update them yourself.

To use this filter you must define a $wp_filter global before WordPress loads, usually in wp-config.php.

Example:

$GLOBALS['wp_filter'] = array(
    'enable_wp_debug_mode_checks' => array(
        10 => array(
            array(
                'accepted_args' => 0,
                'function'      => function() {
                    return false;
                },
            ),
        ),
    ),
);

Parameters

$enable_debug_modebool
Whether to enable debug mode checks to occur. Default true.

Source

if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ) {

Changelog

Version Description
4.6.0 Introduced.