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() 调用,然后验证早期读取不再记录 is_preview 通知,同时正常的 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
- 派生
- 197
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 于 21 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
AdvancedCustomFields/acf#1044 ·
-
True / False ACF control bug on RTL layouts可能已有人在做 @elicohenator 于 44 天前认领。 未关闭
难度 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 于 55 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
AdvancedCustomFields/acf#1032 · 1 条评论 ·
-
Drop trap, acf_after_title可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1029 · 1 条评论 ·
查看 AdvancedCustomFields/acf 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
-
难度 2/5 1-3 小时 新手友好度 62/100
OpenConext/OpenConext-engineblock#2168 ·
维护者通常 5 天内回复
-
mobile-app
难度 2/5 1-3 小时 新手友好度 74/100
Open-Locker/Open-Locker#352 ·
维护者通常 1 天内回复
-
[Bug]: SCIM Users groups[].value is returned as an integer, causing authentik user discovery to fail未关闭
难度 2/5 1-3 小时 新手友好度 62/100
grokability/snipe-it#20006 ·
维护者通常 1 天内回复
-
fixed
难度 2/5 1-3 小时 新手友好度 62/100
firefly-iii/firefly-iii#13150 · 2 条评论 ·
维护者通常 1 天内回复