Seamless clone fields after the first one are returned nested in a flexible content layout

Open Beginner friendly
#589 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Read includes/fields/class-acf-field-clone.php around line 139, where acf_get_fields() expands seamless clone fields with array_splice(). Reproduce with a flexible content layout containing at least two seamless clone fields, then check get_fields() output. Done when each clone’s subfields are flat, matching the described ACF Pro 6.8.6 behavior.

Written by the indexing model from the issue text.

Description

SCF 6.9.8. In acf_get_fields() (includes/fields/class-acf-field-clone.php, around line 139), the
seamless clone filter takes the field count once, before the loop:

  $count = count( $fields );
   while ( $i < $count ) {

Inside the loop, array_splice() replaces each seamless clone with its sub fields, so $fields grows.
The loop stops at the old count, and the later seamless clones are never expanded.

Result: in a flexible content layout with several seamless clones, only the first one is flat.
The next ones come back nested under the clone field name. ACF Pro 6.8.6 returns all of them flat,
so a site that moves from ACF Pro to SCF gets different get_fields() output.

To reproduce: a flexible content field, one layout with 2 or more clone fields in "seamless" mode.
Save a post, call get_fields(): the second clone is an array under its name, not flat.

Fix: count again on each pass.

    -    $count = count( $fields );
    -    while ( $i < $count ) {
    +    while ( $i < count( $fields ) ) {

With this change, get_fields() gives the same output as ACF Pro 6.8.6 for our 221 posts and the
options page.

Dominant language
PHP
Stars
136
Forks
73
Avg merge
18h 21m
Merged PRs (30d)
21

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

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.

More from WordPress/secure-custom-fields

All issues in WordPress/secure-custom-fields

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.