is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu trong includes/revisions.php tại acf_revisions::acf_validate_post_id() và xem xét hook acf/validate_post_id của nó cùng với kiểm tra preview sớm. Tái hiện lệnh gọi get_field() của plugins_loaded khi đã bật WP_DEBUG, sau đó xác minh rằng các lần đọc sớm không còn ghi log thông báo is_preview, trong khi việc xác thực preview thông thường vẫn nguyên vẹn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- PHP
- Star
- 947
- Fork
- 198
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của 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)Có thể đã có người làm @faisalahammad đã nhận 14 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
AdvancedCustomFields/acf#1044 ·
-
True / False ACF control bug on RTL layoutsCó thể đã có người làm @elicohenator đã nhận 36 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
AdvancedCustomFields/acf#1038 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1034 · 3 bình luận ·
-
Bug: class-acf-field-icon_picker.php calls wp_get_attachment_image_url() with string Dashicon slug, causing fatal TypeError on PHP 8+Có thể đã có người làm @antwonw đã nhận 47 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
AdvancedCustomFields/acf#1032 · 1 bình luận ·
-
Drop trap, acf_after_titleCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AdvancedCustomFields/acf#1029 · 1 bình luận ·
Tất cả issue của AdvancedCustomFields/acf
Issue tương tự
-
Bug-Report
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
RSS-Bridge/rss-bridge#5158 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage needed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
kanboard/kanboard#5937 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
octobercms/october#6150 ·
-
Syntax error with CONST-sĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
flarum/framework#5301 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày