"Translation loading for the fork domain was triggered too early" notice on every request (WordPress 6.7+)
还没有人认领这个 Issue。
评估
调研方向
问题出在 inc/Block_Patterns.php:构造函数直接调用 setup_properties(),而该方法调用 __( 'Fork Patterns', 'fork' ) 发生在 init 之前。从这里开始,并在开启 WP_DEBUG_LOG 且 wp-content/languages/themes/fork-en_US.mo 为空的情况下复现。完成标准是:fork 域名的通知不再出现在 debug.log 中,构造函数将 run() 挂接到 init,并且 fork_block_patterns_categories 和 fork_block_patterns 过滤器仍然触发并注册 patterns。
由索引模型根据 Issue 内容生成。
描述
What's wrong
On WordPress 6.7 and later, every page load (front end, admin, REST, WP-CLI) writes this notice to the debug log when WP_DEBUG is on:
PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the fork domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later.
On a test site the log grew by about 500 lines per test session from this notice alone. On a translated site, WordPress also loads Fork's translations earlier than it allows.
Cause
inc/Block_Patterns.php: the constructor calls setup_properties() straight away, and setup_properties() calls __( 'Fork Patterns', 'fork' ). The constructor runs from Core::__construct() while functions.php loads, which is before init. The code has been like this since 1.0.0; WordPress started reporting it in 6.7.
Steps to reproduce
WordPress only shows this notice when a translation file exists for the domain in the site's language. An English site has none, so the notice never shows there.
- Use a site with
WP_DEBUGandWP_DEBUG_LOGon and Fork active. Either set the site language to one Fork has translations for, or (what our QA site does) create an emptywp-content/languages/themes/fork-en_US.mo. - Load any page.
- Open
wp-content/debug.log.
Expected: no notice for the fork domain.
Actual: one notice per request.
Seen on WordPress 6.7.12, 6.8, 7.1.5 and 7.2-RC2, with Fork 1.0.16.
Suggested fix
Call setup_properties() from the init callback instead of the constructor:
public function __construct() {
add_action( 'init', array( $this, 'run' ) );
}
public function run() {
$this->setup_properties();
$this->register_categories();
$this->register_patterns();
}
The fork_block_patterns_categories and fork_block_patterns filters then run at init, which is later than now. Check that nothing hooks them later than that.
- 主要语言
- PHP
- 星标
- 0
- 派生
- 0
- 平均合并
- 1 小时 2 分钟
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Codeinwp/fork 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 1/5 1 小时以内 新手友好度 88/100
-
难度 1/5 1 小时以内 新手友好度 86/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 1/5 1 小时以内 新手友好度 88/100
相似的 Issue
-
Change: check an identifier filter the same way in every tool - the order of somcp_search_orders未关闭consistency enhancement Orders
难度 1/5 1 小时以内 新手友好度 88/100
novalo-dev/Prestashop-MCP-Server#343 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
claude
难度 2/5 1-3 小时 新手友好度 72/100
sprain/sprainocchio#45 ·
维护者通常 1 天内回复
-
sync-en
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
sync-en
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复