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

Abierto Apto para principiantes
#118 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php
Área
backend

Línea de trabajo

El problema está en inc/Block_Patterns.php: el constructor llama directamente a setup_properties(), y ese método llama a __( 'Fork Patterns', 'fork' ) antes de init. Empieza ahí y reproduce con WP_DEBUG_LOG activado y un wp-content/languages/themes/fork-en_US.mo vacío. Está terminado cuando el aviso del dominio fork ya no aparece en debug.log, el constructor engancha run() a init, y los filtros fork_block_patterns_categories y fork_block_patterns siguen disparándose y registrando patrones.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
PHP
Estrellas
0
Forks
0
Merge medio
1 h 2 min
PR fusionados (30 d)
5

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Codeinwp/fork

Todos los issues de Codeinwp/fork

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.