AdvancedCustomFields / AdvancedCustomFields/acf
Uncaught TypeError: Cannot access offset of type string on string: flexible-content - prepare_field_for_import()
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
Getting a PHP Fatal error after uploading ACF Pro on a fresh Wordpress 6.7.1 + PHP8.2 install.
PHP Fatal error:
Uncaught TypeError: Cannot access offset of type string on string in /var/www/html/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php:1467
Stack trace:
#0 /var/www/html/wp-includes/class-wp-hook.php(324): acf_field_flexible_content->prepare_field_for_import(Array)
#1 /var/www/html/wp-includes/plugin.php(256): WP_Hook->apply_filters(Array, Array)
#2 /var/www/html/wp-content/plugins/advanced-custom-fields-pro/includes/acf-hook-functions.php(109): apply_filters_ref_array('acf/prepare_fie...', Array)
#3 /var/www/html/wp-includes/class-wp-hook.php(324): _acf_apply_hook_variations(Array)
#4 /var/www/html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
#5 /var/www/html/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(1626): apply_filters('acf/prepare_fie...', Array)
#6 /var/www/html/wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php(1578): acf_prepare_field_for_import(Array)
#7 /var/www/html/wp-content/plugins/advanced-custom-fields-pro/includes/local-fields.php(404): acf_prepare_fields_for_import(Array)
#8 /var/www/html/wp-content/plugins/advanced-custom-fields-pro/includes/local-fields.php(729): acf_add_local_fields(Array)
#9 /var/www/html/wp-includes/class-wp-hook.php(324): _acf_do_prepare_local_fields(5)
#10 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#11 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#12 /var/www/html/wp-content/plugins/advanced-custom-fields-pro/acf.php(378): do_action('acf/include_fie...', 5)
#13 /var/www/html/wp-includes/class-wp-hook.php(324): ACF->init('')
#14 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#15 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#16 /var/www/html/wp-settings.php(704): do_action('init')
#17 /var/www/html/wp-config.php(139): require_once('/var/www/html/w...')
#18 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...')
#19 /var/www/html/wp-admin/admin.php(34): require_once('/var/www/html/w...')
#20 /var/www/html/wp-admin/plugins.php(10): require_once('/var/www/html/w...')
#21 {main}
thrown in /var/www/html/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1467, referer: http://localhost:8080/wp-admin/update.php?action=upload-plugin
To Reproduce
Steps to reproduce the behavior:
- Build docker-container from
wordpress:6.7.1-php8.2-apache - Upload ACF-Pro & activate plugin
- Refresh page, get window with 'critical error'
- Go to docker-container, and see the error log, reading like the log-message above
Expected behavior
A working ACF-Pro with PHP8.2.
I found a working solution using the proposed solution from this issue: add the code below at line 1493 in the file class-acf-field-flexible-content.php, right after the foreach:
if (!is_array($sub_field)) {
continue;
}
Version Information:
- WordPress Version 6.71.
- PHP Version 8.2
- ACF Version 6.3.11
- Browser [e.g. chrome 103, safari 17]
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with pro/fields/class-acf-field-flexible-content.php at line 1467 and inspect prepare_field_for_import(), then reproduce activation using wordpress:6.7.1-php8.2-apache with ACF Pro 6.3.11. Done means activating and refreshing the plugin no longer produces the reported TypeError or critical error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100