is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)
評価
調査の方向性
includes/revisions.php の acf_revisions::acf_validate_post_id() から始め、その acf/validate_post_id hook と早期の preview チェックを確認します。WP_DEBUG を有効にして plugins_loaded の get_field() 呼び出しを再現し、その後、通常の preview 検証を維持したまま、早期の読み取りで is_preview 通知がログに記録されなくなっていることを確認します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- PHP
- スター
- 948
- フォーク
- 198
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
AdvancedCustomFields/acf のほかの issue
-
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)対応中かも @faisalahammad が 9 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
AdvancedCustomFields/acf#1044 ·
-
True / False ACF control bug on RTL layouts対応中かも @elicohenator が 31 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
AdvancedCustomFields/acf#1038 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1034 · コメント 3 件 ·
-
Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+対応中かも @antwonw が 43 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
AdvancedCustomFields/acf#1032 · コメント 1 件 ·
-
Drop trap, acf_after_title対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AdvancedCustomFields/acf#1029 · コメント 1 件 ·
AdvancedCustomFields/acf の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
MagnaCapax/PMSS#1142 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Native-arrow select renders a second Jetpack chevron再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Automattic/static-site-importer#2294 ·
メンテナーはふだん 1 日以内に返信
-
bug 🐛
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
netalertx/NetAlertX#1856 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100