Skip to content

acf_rendered_block() preview render leaks acf_setup_meta() state (no matching acf_reset_meta) #455

@cbravobernal

Description

@cbravobernal

Description

The preview paths of acf_rendered_block() / acf_rendered_block_v3() call acf_setup_meta() for post-render validation but never call the matching acf_reset_meta(), leaving block-scoped local meta active after the function returns.

This compounds badly with how local meta works: while acf_setup_meta() is active for a post id, ACF_Local_Meta's pre_load_metadata filter returns __return_null for any meta name not present in the local set (includes/local-meta.php:194-203) — shadowing real database values for that post. So after a block preview render, unrelated get_field() calls for the same post id can silently return null.

Affected code

  • includes/blocks.php (acf_rendered_block / acf_rendered_block_v3 preview paths)
  • Interplay: includes/local-meta.php:194-203

Reproduction

Repro documented in #450: tests/php/includes/blocks/test-blocks-render.php (tear_down resets the leaked state manually and carries the NOTE comment); the shadowing behavior itself is characterized in tests/php/includes/test-local-meta.php (test_local_meta_shadows_missing_names).

Suggested fix

Pair every acf_setup_meta() in the preview/validation paths with acf_reset_meta() (try/finally semantics or immediately after the validation read).

Found during the 2026-06 test campaign (see PR #450).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions