"Translation loading for the fork domain was triggered too early" notice on every request (WordPress 6.7+)

未關閉 適合新手
#118 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
php
領域
backend

研究方向

問題出在 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.

  1. Use a site with WP_DEBUG and WP_DEBUG_LOG on and Fork active. Either set the site language to one Fork has translations for, or (what our QA site does) create an empty wp-content/languages/themes/fork-en_US.mo.
  2. Load any page.
  3. 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 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Codeinwp/fork 的其他 Issue

查看 Codeinwp/fork 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。