钩子文档

doing_it_wrong_trigger_error

💡 云策文档标注

概述

doing_it_wrong_trigger_error 是一个 WordPress 过滤器,用于控制是否在 _doing_it_wrong() 调用时触发错误。它允许开发者根据条件调整错误触发行为,常用于调试和自定义错误处理。

关键要点

  • 过滤器名称:doing_it_wrong_trigger_error,用于过滤 _doing_it_wrong() 的错误触发。
  • 参数:包括 $trigger(布尔值,默认 true)、$function_name(字符串)、$message(字符串)和 $version(字符串),分别控制错误触发、函数名、错误信息和 WordPress 版本。
  • 使用场景:在 WP_DEBUG 启用时,通过 apply_filters 应用此过滤器,可自定义错误处理逻辑。
  • 版本历史:WordPress 5.1.0 添加了 $function_name、$message 和 $version 参数,3.1.0 版本引入此过滤器。

代码示例

if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function_name, $message, $version ) ) {

📄 原文内容

Filters whether to trigger an error for _doing_it_wrong() calls.

Parameters

$triggerbool
Whether to trigger the error for _doing_it_wrong() calls. Default true.
$function_namestring
The function that was called.
$messagestring
A message explaining what has been done incorrectly.
$versionstring
The version of WordPress where the message was added.

Source

if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function_name, $message, $version ) ) {

Changelog

Version Description
5.1.0 Added the $function_name, $message and $version parameters.
3.1.0 Introduced.