Classic Editor preview shows published field values on every other click when the post has `_acf_changed` saved in its meta
还没有人认领这个 Issue。
评估
调研方向
Start with includes/revisions.php, especially acf_revisions::wp_preview_post_fields() and the _acf_changed revision registration described in the report. Trace how WordPress creates and restores Classic Editor autosaves, then reproduce the alternating preview behavior with a published post whose _acf_changed meta is 1. Done means repeated previews keep showing the current unsaved field values without leaving the request flag on the parent post.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
In the Classic Editor, on a published post, if the post's own meta contains _acf_changed with a value of 1, then previewing a change to an ACF field only works on every other click. On alternate clicks WordPress deletes the autosave, and the preview shows the published values.
This came to us through a WPGraphQL for ACF report (https://github.com/wp-graphql/wp-graphql/issues/4529), but it reproduces in WordPress's own front-end preview with only ACF PRO and the Classic Editor plugin active.
The cause, as far as I can tell:
acf_revisions::wp_preview_post_fields()(revisions.php#L150-L163) adds_acf_changedto the revision fields on a preview request, so thatwp_create_post_autosave()sees the autosave as different from the post and updates it rather than deleting it.wp_create_post_autosave()compares the posted_acf_changed('1') against$post->_acf_changed, whichWP_Post::__get()reads from the post's meta. Normally that's empty, so the values differ and the autosave is kept.- Since 6.2.6,
_acf_changedis registered withrevisions_enabled(revisions.php#L52-L78), so restoring an autosave from the Revisions screen copies_acf_changed = 1onto the post itself, and later updates don't remove it. - Once the post has
1saved, the comparison matches. If title, content and excerpt are unchanged too, WordPress decides the autosave is identical to the post and deletes it. The next click creates a fresh autosave, the one after deletes it again, and so on.
To Reproduce
- Activate ACF PRO and the Classic Editor plugin.
- Create a field group with a Text field, shown on Pages.
- Create a page, set the field to
A, and publish it. Render the field in the template, or use any other way to view the preview. - Change the title and set the field to
B, click Preview, then leave the editor without updating. - Go to the page's Revisions screen and click "Restore This Autosave".
wp post meta get <page-id> _acf_changednow returns1. Clicking Update in the editor afterwards doesn't clear it.- In the editor, change only the field to
Cand click Preview: the preview showsC. - Click Preview again without changing anything: the preview shows the published value, and the autosave has been deleted.
- Keep clicking: it alternates between the two.
Deleting the meta (wp post meta delete <page-id> _acf_changed) makes every click work again. Changing the title or content along with the field also avoids it.
Expected behavior
Every preview click shows the current unsaved field values. _acf_changed is a request flag, so it shouldn't end up persisted on the parent post, or the comparison shouldn't depend on what's stored there.
Possible fixes, in case they're useful:
- don't restore
_acf_changedonto the parent post inwp_restore_post_revision(or delete it from the parent afterwards) - in
wp_preview_post_fields(), set a value that can't match stored meta, for example a timestamp or a random string, rather than relying on the post not having1saved
The block editor isn't affected, because the REST autosave controller compares meta strictly and always sees a difference.
Version Information:
- WordPress 7.0
- PHP 8.3.35
- ACF PRO 6.8.4 (the original report was on 6.3.8, which has the same revisions code)
- Classic Editor 1.7.0
- Chromium (headless, driven by Playwright)
Additional context
AdvancedCustomFields/acf#903 covers block editor previews and is a different problem.
- 主要语言
- PHP
- 星标
- 947
- 派生
- 198
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
AdvancedCustomFields/acf 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
AdvancedCustomFields/acf#1056 ·
-
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 于 30 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
AdvancedCustomFields/acf#1044 ·
-
is_preview was called incorrectly notice on every early get_field() since 6.8.10 (acf_revisions::acf_validate_post_id)可能已有人在做 @faisalahammad 于 30 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1041 · 1 条评论 ·
-
True / False ACF control bug on RTL layouts可能已有人在做 @elicohenator 于 53 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
AdvancedCustomFields/acf#1038 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1034 · 3 条评论 ·
查看 AdvancedCustomFields/acf 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 3 天内回复
-
难度 1/5 1 小时以内 新手友好度 91/100
benjaminkott/bootstrap_package#1675 ·
-
sync-en
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
[Sync EN] Formatting improvements to "Large Objects (LOBs)" docs (#6056)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭sync-en
难度 1/5 1 小时以内 新手友好度 74/100
维护者通常 1 天内回复