Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Robert

Fatal TypeError in the ACF addon when a group sub field is false

Opening column settings for a custom post type list screen fatals in the ACF addon.

Admin Columns Pro 7.1.6
Page: wp-admin → Settings → Admin Columns, list screen “dog”
Request: admin-ajax.php?action=ac-list-screen-settings&list_key=dog
Site: https://www.windyknollgoldens.com/

[b]Error[/b]

[code]
Uncaught TypeError: ACA\ACF\FieldRepository::create_group_field(): Argument #1 ($field) must be of type array, false given, called in .../addons/acf/classes/FieldRepository.php on line 150 and defined in .../addons/acf/classes/FieldRepository.php:156
[/code]

The settings request dies while the ACF column factory loads fields for that list screen. The public site is unaffected.

[b]Cause[/b]

create_group_fields() loops $group_field[‘sub_fields’] and passes each item to create_group_field(), which requires an array:

[code]
foreach ($group_field['sub_fields'] ?? [] as $field) {
if (in_array($field['type'], $exclude, true)) {
continue;
}

$fields[] = $this->create_group_field($field, $group_field);
}
[/code]

One sub field was false. Reading $field[‘type’] on false only warns, so the exclude check does not skip it, and the array type hint fatals.

ACF puts that false there. acf_get_fields() appends whatever acf_get_field() returns, and acf_get_field() returns false when a child cannot be loaded (deleted or trashed sub field, a missing local PHP/JSON field, or an acf/load_field callback). The group field’s load_field() copies that list, false included, into sub_fields.

[b]Fix[/b]

Skip anything that is not a field array before using it:

[code]
foreach ($group_field['sub_fields'] ?? [] as $field) {
if (! is_array($field)) {
continue;
}
// existing type exclude and create_group_field() call
}
[/code]

This is only in the Pro ACF addon (addons/acf/classes/FieldRepository.php). The free plugin does not contain this code.

2 days, 19 hours ago
Robert

My attempt to create bold text and code text in this support request didn’t quite work out. I should have just used these buttons. Sorry about that. Hopefully the request is still easy to understand. Unfortunately, I don’t see a button to edit in anywhere.

2 days, 19 hours ago