Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#1,041 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

@faisalahammad đang làm issue này rồi.

Từ ngày 12/10/2026.

  • #1049 của @faisalahammad — đang mở

Đá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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend

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_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.

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AdvancedCustomFields/acf

Tất cả issue của AdvancedCustomFields/acf

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.