Critical - ACF Blocks V3 - field values not saved to metadata until changed
还没有人认领这个 Issue。
评估
调研方向
使用提供的 block.json 和 PHP 渲染模板,在 WP 6.8.3 和 ACF Pro 6.6.1 下重现该问题,并将 blockVersion 3 与 v2 模式设置进行比较。跟踪插入区块时初始字段值和区块元数据的保存方式。完成标准是:默认字段值会保存到区块元数据中,无需手动更改,即使存在 InnerBlocks 也是如此。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
When using v3 blocks, field values are not saved to the block metadata until a field value is specifically changed. This results in effects such as default values not working.
To Reproduce
Steps to reproduce the behavior:
- Create the block and field group via the code below.
- Add a new post, and insert the block. You will see the checkbox is checked, and the get_field code outputs that it is checked.
- Publish the post, and view it on the front-end. It says the checkbox is not checked.
- Reload the editor, and it will also say it is not checked.
- Click on the block to edit it, and the editor preview will quickly changed to checked again.
- During any stage of the above, switch to the code editor, and see the block metadata is empty.
- Repeat all of the above, replacing
"blockVersion": 3with"mode":"preview"in block.json, to show that it used to work correctly in v2 blocks.
Note that if you remove the InnerBlocks line from the render template, you get slightly different results - the preview shows correctly in the editor even without clicking the block, but it still doesn't save.
Only by unchecking and then rechecking the checkbox will it save.
Expected behavior
Block fields should be saved to the block when first inserted.
Screenshots or Video
https://github.com/user-attachments/assets/5dc16eae-0ff7-42a2-9194-06bbc0b5ec5d
Code
Field export:
{
"key": "group_68d08a422dee3",
"title": "Test block",
"fields": [
{
"key": "field_68d08a4483410",
"label": "Test field",
"name": "test_field",
"aria-label": "",
"type": "true_false",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "Test field",
"default_value": 1,
"allow_in_bindings": 0,
"ui": 0,
"ui_on_text": "",
"ui_off_text": ""
}
],
"location": [
[
{
"param": "block",
"operator": "==",
"value": "acf\/testblock"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": true,
"description": "",
"show_in_rest": 0,
"display_title": ""
}
]
block.json:
{
"name": "acf/testblock",
"title": "Test block",
"acf": {
"renderTemplate": "testblock.php",
"blockVersion": 3
}
}
render template:
<p><?php if (get_field('test_field')) echo 'Checkbox is checked'; else echo 'Checkbox is not checked'; ?></p>
<InnerBlocks />
Version Information:
- WP 6.8.3
- ACF Pro 6.6.1
- 主要语言
- PHP
- 星标
- 946
- 派生
- 197
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
AdvancedCustomFields/acf 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1041 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 86/100
AdvancedCustomFields/acf#1038 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1034 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 86/100
AdvancedCustomFields/acf#1032 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
AdvancedCustomFields/acf#1029 · 1 条评论 ·
查看 AdvancedCustomFields/acf 的全部 Issue
相似的 Issue
-
sync-en
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
bug Feature: Kiosk
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Infrastructure: actions Module: zmscitizenapi Module: zmsentities php Type: Bug unit tests
难度 2/5 1-3 小时 新手友好度 88/100
it-at-m/eappointment#3480 ·
维护者通常 1 天内回复
-
HttpClient
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
CI: composer install fails — league/flysystem 1.x blocked by security advisory GHSA-cxf4-7mrp-vvpr未关闭devops type: bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复