Undefined array key “locales” – $Haystack
-
It’s been few weeks now that I have the following warning message on the main plugin page when I click on the Loco translate left menu tab :
Warning: Undefined array key “locales” in /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/src/data/Preferences.php on line 162
And there are dozens of this very same warning message.
When I check line 162 of the stated file, it says:
162 $haystack = $this->locales;
I really don’t know what to do since I’m not very familiar with code.
Could you please help? Thanks!
The page I need help with: [log in to see the link]
-
Thanks for reporting.
I understand the error, but I don’t understand how it can occur. The “locales” key should always exist, but for some reason it does not.
What version of PHP are you running?
Possibly you can fix it by opening the preferences and saving them. Go to Loco Translate > Settings and select the “User options” tab. Then just click the “Save settings” button.
I’m running PHP 8.
When I go to Loco Translate > Settings and click on the user options tab I get this :
Translator credits : “Name Surname”
Restreindre locales : “<br /><b>Warning</b>: Undefined array key ” /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/tpl/admin/config/prefs.php on line 36
Fatal error: Uncaught TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/tpl/admin/config/prefs.php:36 Stack trace: #0 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/tpl/admin/config/prefs.php(36): implode(', ', NULL) #1 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/src/mvc/View.php(271): include('/homepages/10/d...') #2 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/src/mvc/View.php(220): Loco_mvc_View->execTemplate('/homepages/10/d...') #3 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/src/mvc/View.php(207): Loco_mvc_View->buffer() #4 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/src/mvc/AdminController.php(234): Loco_mvc_View->render('admin/config/pr...') #5 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/src/admin/config/PrefsController.php(46): Loco_mvc_AdminController->view('admin/config/pr...', Array) #6 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/src/mvc/AdminRouter.php(244): Loco_admin_config_PrefsController->render() #7 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-includes/class-wp-hook.php(303): Loco_mvc_AdminRouter->renderPage('') #8 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array) #9 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-includes/plugin.php(470): WP_Hook->do_action(Array) #10 /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-admin/admin.php(259): do_action('loco-translate_...') #11 {main} thrown in /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/tpl/admin/config/prefs.php on line 36 Une erreur critique est survenue sur ce site. Veuillez consulter la boite de réception de l’e-mail d’administration de votre site pour plus d’informations. En apprendre plus sur le débogage de WordPress.-
This reply was modified 4 years, 7 months ago by
ibrabulle.
Thanks for the extra info. I will try to reproduce this problem under PHP 8.0.
Is there anything else you can tell me? Such as what version of Loco Translate you are running, when you original installed it, and whether you had the same error in previous versions, or whether it started after upgrading to a particular version?
It’s v 2.5.5, I installed it in 2017 and didn’t see the issue back then. I don’t check my plugins often but I may have seen one warning line previously, I’m not sure. But now for instance I have approximately 1000 lines, the same ones, saying :
Warning: Undefined array key “locales” in /homepages/10/d679544763/htdocs/clickandbuilds/MiswaShop/wp-content/plugins/loco-translate/src/data/Preferences.php on line 162
Sometimes it’s just 20 lines, and sometimes hundreds, it depends.
Ok, thanks. I’m afraid I don’t understand it. The logic of the code ensures the key always exists. There are things I can do to avoid errors when the key is missing, but as the situation should be impossible I’d like to understand it first. Whatever the cause, it may affect other things and I don’t want to mask it.
Do you have user preferences saved? You can check with this SQL query:
SELECT meta_value FROM wp_usermeta WHERE meta_key = 'loco_prefs';I think I’ve fixed this. Please try the current dev version. https://localise.biz/wordpress/plugin/developers
So sorry for the late reply.
I didn’t get your first message with the SQL query. I’m a beginner.
Anyways, I installed your dev version and it works.
Should I wait for a final version or is it OK to keep this dev version?
Thanks Tim!I’m not ready to deploy a new release yet that contains this fix.
If the dev version works then as soon as you’ve saved your user preferences the error should not occur again even if you roll back to the current “stable” release. (I’ve not tested this)
You can keep the dev version if you want, but it can only be updated manually. I suggest you re-install 2.5.5 and if the errors have gone then job done. Otherwise you’ll have to keep a eye out for version 2.5.6 and install it when it’s live.
I’m marking as resolved as the bug was reproduced and fixed.
I re-installed 2.5.5 and the error messages popped again. So back to 2.5.6-dev. Thanks!
Thanks for the follow up.
As WordPress 5.8.2 has been released I will release 2.5.6 very soon.
Great! Thanks for your support!
-
This reply was modified 4 years, 7 months ago by
The topic ‘Undefined array key “locales” – $Haystack’ is closed to new replies.