Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)

Aperta Adatta ai principianti
#1,041 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

Inizia in includes/revisions.php, in acf_revisions::acf_validate_post_id(), e verifica il relativo hook acf/validate_post_id e il controllo anticipato di preview. Riproduci la chiamata a get_field() di plugins_loaded con WP_DEBUG abilitato, quindi verifica che le letture anticipate non registrino più l'avviso is_preview, mentre la normale validazione di preview rimanga intatta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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_DEBUG enabled
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
  1. Enable WP_DEBUG and WP_DEBUG_LOG.

  2. Add to any plugin:

    add_action( 'plugins_loaded', function () {
        get_field( 'any_field', 'option' );
    } );
    
  3. 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.

Lingua principale
PHP
Stelle
946
Fork
197
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AdvancedCustomFields/acf

Tutte le issue di AdvancedCustomFields/acf

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.