is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Comienza en includes/revisions.php, en acf_revisions::acf_validate_post_id(), y revisa su hook acf/validate_post_id y la comprobación temprana de preview. Reproduce la llamada a get_field() de plugins_loaded con WP_DEBUG habilitado y, después, verifica que las lecturas tempranas ya no registren el aviso de is_preview, mientras la validación normal de preview siga intacta.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
is_preview was called incorrectly notice on every early get_field() since 6.8.10
Environment
- ACF PRO 6.8.10
- WordPress 7.0 (multisite)
- PHP 8.4
WP_DEBUGenabled
Description
Since 6.8.10, any get_field() / get_option()-style ACF read made before WordPress creates the main query triggers a PHP notice:
PHP Notice: Function is_preview was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. (This message was added
in version 3.1.0.) in wp-includes/functions.php on line 6131
The notice fires on every such call, so production logs fill up quickly. It also breaks sites that convert notices to exceptions: with Whoops in development, the request ends in
a 500.
Cause
acf_revisions::acf_validate_post_id() (includes/revisions.php) is hooked to acf/validate_post_id, so it runs on every field read. In 6.8.10 its early bail changed:
- // bail early if no preview in URL
- if ( ! isset( $_GET['preview'] ) ) {
+ // Bail early if not a well-formed WordPress preview context.
+ if ( ! is_preview() ) {
return $post_id;
}
is_preview() calls _doing_it_wrong() when the global $wp_query is not set yet. WordPress only creates it in wp-settings.php after plugins_loaded. Reading options while
plugins load (settings, feature flags, service bootstrapping) is a common and legitimate pattern, and before 6.8.10 it produced no notice.
Steps to reproduce
-
Enable
WP_DEBUGandWP_DEBUG_LOG. -
Add to any plugin:
add_action( 'plugins_loaded', function () { get_field( 'any_field', 'option' ); } ); -
Load any front-end page.
Expected
No notice, as in 6.8.9 and earlier.
Actual
The is_preview was called incorrectly notice is logged on every call.
Suggested fix
Before the main query exists, is_preview() returns false anyway, so bailing out without calling it keeps the behavior identical:
global $wp_query;
if ( ! isset( $wp_query ) || ! is_preview() ) {
return $post_id;
}
Workaround
Right after ACF loads, we replace ACF's callback on acf/validate_post_id with a wrapper. The wrapper calls acf()->revisions->acf_validate_post_id() only when
$GLOBALS['wp_query'] is set.
- Lenguaje dominante
- PHP
- Estrellas
- 948
- Forks
- 198
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de AdvancedCustomFields/acf
-
PHP 8.5: "Using null as an array offset" deprecation in ACF_Data::is() when rendering a block with empty data (local-meta.php is_request)Posiblemente ocupada @faisalahammad la tomó hace 9 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
AdvancedCustomFields/acf#1044 ·
-
True / False ACF control bug on RTL layoutsPosiblemente ocupada @elicohenator la tomó hace 32 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
AdvancedCustomFields/acf#1038 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
AdvancedCustomFields/acf#1034 · 3 comentarios ·
-
Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+Posiblemente ocupada @antwonw la tomó hace 43 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
AdvancedCustomFields/acf#1032 · 1 comentario ·
-
Drop trap, acf_after_titlePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
AdvancedCustomFields/acf#1029 · 1 comentario ·
Todos los issues de AdvancedCustomFields/acf
Issues similares
-
sync-en
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
Los mantenedores suelen responder en 1 día
-
sync-en
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
Source item status is not saved when stock is deducted on shipment (stays "In Stock" at qty 0)AbiertoIssue: ready for confirmation
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Перевод устарел
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
LinkStackOrg/LinkStack#1014 · 2 comentarios ·