[Resolved] Error Triggered During CDB Form Translation (WPML 4.7.6)
This thread is resolved. Here is a description of the problem and solution.
Problem: The client reported a bug in WPML version 4.7.6 where an error occurs when clicking the '+' button on a page with custom fields. The error message displayed is: 'Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array.' This issue was linked to the handling of XML configurations for serialized custom fields. Solution: We identified that the XML file for the custom forms was misconfigured. Specifically, the 'optinText' field was expected to directly provide a text value for translation, but it was actually stored inside an array. To resolve this, we adjusted the XML configuration to correctly map the 'optinText' field as follows:
After modifying the XML and clearing any existing translation jobs for this form, the error was resolved, and the translation process proceeded without issues. We recommend the client to apply this XML configuration change and verify the results.
If this solution does not apply to your situation, or if it seems outdated, please check the related known issues and confirm that you have the latest versions of themes and plugins installed. If the problem persists, we highly recommend opening 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.
Contesto del problema:
I am trying to report a bug related to the WPML module version 4.7.6. An error is triggered when clicking '+' on a page with custom fields. The error is: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array. I believe adding a fix in the function match_in_order before array_keys($whitelist) will resolve the issue. The code is located in sitepress-multilingual-cms/classes/settings/class-wpml-tm-serialized-custom-field-package-handler.php. More details can be found in this forum thread: WPML Error Discussion here https://wpml.org/it/forums/topic/uncaught-typeerror-array_keys-argument-1-array-must-be-of-type-array/.
Sintomi:
An error is triggered when clicking '+' on a page with custom fields. The error message is: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array.
Domande:
What causes the Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array?
Is the proposed fix in the function match_in_order (in sitepress-multilingual-cms/classes/settings/class-wpml-tm-serialized-custom-field-package-handler.php) appropriate for resolving this issue?
if ( ! is_array( $whitelist ) ) {
return false;
}
Can you implement it or is there a hook to force the $whitelist variable as an array ? or maybe a setting to configure tat I would have missed ?
Hello Drazen,
Thank you for your prompt response. I switched to the default WordPress theme, Twenty Twenty-Five, and disabled plugins but I am still experiencing the same issue.
Please let me know how we can proceed from here.
Best regards,
Please share the access details of your website, so I can log in and take a look. Preferblu staging, where I can test same steps as you and do some debugging.
I’m enabling a private message for the following reply.
We have strict policies regarding privacy and access to your information.
- Please backup the site files and database before providing us access.
- If you have a staging site where the problem can be reproduced, it is better to share access to the staging site.
If you can show us issue or WPML bug with simple example code or compatible plugin / themes we can help further, but I am afraid we can not support custom solutions and debug them.
For tasks beyond our standard support, you can get help from certified WPML Contractors.
Hope this makes sense, let me know if any further doubts or questions.
Hey Dražen thanks for checking but could you give me a bit more details, which plugin(s) according to you is breaking stuff ??
How did you checked?
Thanks
Oh yes indeed the issue happens when a user wants to translate a form with our custom plugin indeed.
However, from a development point of you maybe you could tell me if there is a hook to make sure the function match_in_order (in sitepress-multilingual-cms/classes/settings/class-wpml-tm-serialized-custom-field-package-handler.php) does not crash when the $whitelist variable is not an array? maybe there is a setting not configured properly ? any workaround ?
Or, will your dev team add such a patch in future version:
I checked a bit further, and you might be right, even if it is being caused by custom plugin, it seems we should implement a check to avoid fatal error.
I have escalated ticket to 2nd tier to check and confirm / escalate further if needed.
we have checked, and some things feel a bit odd. Did you do any adjustment to WPML code or files?
For us to continue and confirm the issue / check further, it would be required to reproduce similar issue on next test site.
The error points to a deeper issue. We could hide it by adding an array check, but the real problem might still be there and could cause translation issues later, so we need to further check.
- hidden link
You can add some simple example code to show us a bug in our code, or you can install your custom plugin and reproduce issue there.
I am afraid it is not possible, as this is test server.
But if you can you can show us an with just simple example code, or you can install file manager and add plugin like that. Also I think it will work even if you install it like regular plugin.
Note since this is custom plugin and coding, we might not be able to help further.