AdvancedCustomFields / AdvancedCustomFields/acf

Block preview with group or repeater field not working

Open
#575 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Since ACF 5.11 fixed a security issue with acf_get_value() function, checking if field really exists, passing example data in acf_register_block_type() for group of repeater field does not work anymore.

Example block fields

"fields": [
{
  "key": "field_6183b15180469",
  "label": "Text left",
  "name": "text_left",
  "type": "group",
  "instructions": "",
  "required": 0,
  "conditional_logic": [
      [
          {
              "field": "field_6183ae54e27bc",
              "operator": "==",
              "value": "text"
          }
      ]
  ],
  "wrapper": {
      "width": "50",
      "class": "",
      "id": ""
  },
  "layout": "block",
  "sub_fields": [
      {
          "key": "field_6183b17b8046a",
          "label": "Title",
          "name": "text_title",
          "type": "text",
          "instructions": "",
          "required": 0,
          "conditional_logic": 0,
          "wrapper": {
              "width": "",
              "class": "",
              "id": ""
          },
          "default_value": "",
          "placeholder": "",
          "prepend": "",
          "append": "",
          "maxlength": ""
      },
      {
          "key": "field_6183b19b8046b",
          "label": "Text",
          "name": "text",
          "type": "wysiwyg",
          "instructions": "",
          "required": 0,
          "conditional_logic": 0,
          "wrapper": {
              "width": "",
              "class": "",
              "id": ""
          },
          "default_value": "",
          "tabs": "all",
          "toolbar": "full",
          "media_upload": 1,
          "delay": 0
      }
  ]
  }
]

In version 5.10 we would pass the example data as follows

[
 'text_left' => [
    'text_title' => 'Lorem ipsum dolor',
    'text'       => 'Pellentesque tincidunt nulla nisi, eget vehicula turpis tincidunt ut. Fusce pharetra justo nulla, sed porttitor nunc varius faucibus.',
  ]
]

In version 5.11 the previous example does not work anymore, or neither passing fields as they are saved to block meta (eg using text_left_text_title as key).

Props to @eliaskau for finding this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with includes/acf-value-functions.php around the acf_get_value() field-existence check, then trace how acf_register_block_type() handles example data for group and repeater fields. Confirm the behavior against the provided nested text_left example and saved block-meta keys; done means previews accept the example data without undoing the security fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.