You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress 6.7中_load_textdomain_just_in_time警告屏蔽问题求助

屏蔽WordPress 6.7中_load_textdomain_just_in_time错误警告的正确方法

针对WordPress 6.7版本中wp-includes/l10n.php第6114行抛出的Function _load_textdomain_just_in_time was called incorrectly.警告,可通过wp_trigger_error_run钩子精准拦截,具体实现代码如下:

if ( WP_DEBUG ) {
    // 高优先级挂载钩子,确保先执行拦截逻辑
    add_filter( 'wp_trigger_error_run', 'block_load_textdomain_just_in_time_warning', 999, 5 );
    
    function block_load_textdomain_just_in_time_warning( $run, $message, $type, $file, $line ) {
        // 精准匹配目标错误的特征:信息、文件、行号
        if ( 
            $message === 'Function _load_textdomain_just_in_time was called incorrectly.'
            && str_ends_with( $file, 'wp-includes/l10n.php' )
            && $line === 6114
        ) {
            return false; // 返回false阻止该错误触发输出
        }
        
        return $run; // 其他错误保持默认输出逻辑
    }
}

关键说明:

  1. 参数完整传递:wp_trigger_error_run钩子支持最多5个参数,必须在add_filter中指定5作为第四个参数,才能拿到错误信息、文件路径、行号等关键判断条件,这是之前代码失效的常见原因。
  2. 高优先级设置:将钩子优先级设为999,确保拦截逻辑在错误触发前执行。
  3. 调试环境限定:通过WP_DEBUG判断,仅在开启调试的本地/预发布站点生效,不影响生产环境。

将上述代码添加到当前主题的functions.php文件末尾,或封装为独立自定义插件加载即可生效。

内容的提问来源于stack exchange,提问作者Chris Pink

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 00:40:05