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

Đang mở Phù hợp với người mới
#118 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend

Hướng nghiên cứu

Vấn đề nằm ở inc/Block_Patterns.php: constructor gọi trực tiếp setup_properties(), và phương thức đó gọi __( 'Fork Patterns', 'fork' ) trước init. Hãy bắt đầu từ đó, và tái hiện với WP_DEBUG_LOG được bật và một wp-content/languages/themes/fork-en_US.mo rỗng. Hoàn tất khi thông báo domain fork không còn xuất hiện trong debug.log, constructor hook run() vào init, và các filter fork_block_patterns_categories và fork_block_patterns vẫn kích hoạt và đăng ký patterns.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
PHP
Star
0
Fork
0
Merge trung bình
1 giờ 2 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Codeinwp/fork

Tất cả issue của Codeinwp/fork

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.