"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 天內回覆