钩子文档

deprecated_function_trigger_error

💡 云策文档标注

概述

deprecated_function_trigger_error 是一个 WordPress 过滤器,用于控制是否在调用已弃用函数时触发错误。它通常与 WP_DEBUG 设置结合使用,以帮助开发者在调试环境中识别和更新过时的代码。

关键要点

  • 这是一个过滤器,允许开发者自定义是否对已弃用函数触发错误。
  • 默认值为 true,表示在 WP_DEBUG 启用时通常会触发错误。
  • 常用于 _deprecated_function() 函数中,以标记和通知函数已弃用。

代码示例

if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
    // 触发错误的代码逻辑
}

注意事项

  • 此过滤器自 WordPress 2.5.0 版本引入,确保在兼容版本中使用。
  • 仅在 WP_DEBUG 为 true 时生效,生产环境中通常应禁用以避免性能影响。

📄 原文内容

Filters whether to trigger an error for deprecated functions.

Parameters

$triggerbool
Whether to trigger the error for deprecated functions. Default true.

Source

if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {

Changelog

Version Description
2.5.0 Introduced.