[Resolved] Error when using with ACF flexible content field
This thread is resolved. Here is a description of the problem and solution.
Problem: If you're experiencing issues with editing ACF flexible content fields and encountering a PHP Fatal error related to type-safety issues in theme code on translated pages, along with a PHP Notice about incorrect translation loading, we can help. Solution: First, ensure you have a backup of your site. Then, make the following changes in the
We tested this solution locally and it resolved the issues. If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket at WPML support forum.
100% of people find this useful.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
ACF flexible content field cannot be edited. When tryng to change the settings, the following error comes up:
PHP Fatal error: Uncaught InvalidArgumentException: item should be a Collection or an array or an object in /var/www/vhosts/zebedeedemo.com/epgglobal-dev.zebedeedemo.com/wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Obj.php:112
There is also a recurring error
PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the acf domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/zebedeedemo.com/epgglobal-dev.zebedeedemo.com/wp-includes/functions.php on line 6131
The site works OK on the front end, including translations
Using the following plugins
Advanced Custom Fields Multilingual Version 2.1.5 by OnTheGoSystems
Advanced Custom Fields PRO Version 6.7.0.2 by WP Engine
WPML Multilingual CMS Version 4.8.6 by OnTheGoSystems
Also, when trying to edit the page we received the attached warning, does it mean we cannot use the flag at the top to change the language to be edited?
I checked the theme and the affected line relates to testimonial logos, but all the French translations have logos attached so I can't quite see the issue.
"Also, when trying to edit the page we received the attached warning, does it mean we cannot use the flag at the top to change the language to be edited?"
Since the home page is set to use the WordPress Editor, the message should not show. I checked again, and it's not there. You can ignore it, if it shows again, since you have the "WordPress Editor" option activated for the home page.
______
Now, as to the issue itself, I'm lost. Can you please clarify?
1. Did you follow the steps, and cleaned up the translated field groups, as instructed?
2. I re-saved a ACF field group and had no errors. The error you shared above is new one? If so, where does it happen and how can I reproduce it?
3. Are you having any issues with your translated content?
If possible, let's try to check one thing at a time. It's unproductive to check many things in parallel.
Thanks for sharing. I was able to properly understand the issue now.
In summary, what's happening, is that $loop_item_logo is expected to be an array (with keys like ['url'], ['alt']), but on translated pages, it's returning a string instead.
I also noticed that the ACF fields are not editable inside the pages. Can you fix that, so we can proceed the check how those values are being handled?
I recommend that you create a staging version of the website, and check how those fields behave with other plugins (including WPML) deactivated. This way, you can work on a cleaner environment.
Thank you for waiting. What is happening, is not a WPML bug per se. WPML is exposing a latent type-safety issue in the theme code that only surfaces on translated pages.
What is actually happening:
get_field( 'logo', $latest_array_id ) is assumed to always return an ACF image array:
[ 'url' => ..., 'alt' => ... ]
That assumption is unsafe.
To work it around, please ensure to have a backup and make the following changes on the /public/wp-content/themes/epgglobal/components/builder_page.php file: