Title: Undefined array key &#8220;locales&#8221; &#8211; $Haystack
Last modified: October 20, 2021

---

# Undefined array key “locales” – $Haystack

 *  Resolved [ibrabulle](https://wordpress.org/support/users/ibrabulle/)
 * (@ibrabulle)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fundefined-array-key-locales-haystack%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Plugin Author [Tim W](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-14988623)
 * 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.
 *  Thread Starter [ibrabulle](https://wordpress.org/support/users/ibrabulle/)
 * (@ibrabulle)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-14990234)
 * 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](https://wordpress.org/support/users/ibrabulle/).
 *  Plugin Author [Tim W](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-14991872)
 * 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?
 *  Thread Starter [ibrabulle](https://wordpress.org/support/users/ibrabulle/)
 * (@ibrabulle)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-14992643)
 * 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.
 *  Plugin Author [Tim W](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-14992674)
 * 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';`
 *  Plugin Author [Tim W](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-14992817)
 * I think I’ve fixed this. Please try the current dev version. [https://localise.biz/wordpress/plugin/developers](https://localise.biz/wordpress/plugin/developers)
 *  Thread Starter [ibrabulle](https://wordpress.org/support/users/ibrabulle/)
 * (@ibrabulle)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-15015587)
 * 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!
 *  Plugin Author [Tim W](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-15050226)
 * 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.
 *  Thread Starter [ibrabulle](https://wordpress.org/support/users/ibrabulle/)
 * (@ibrabulle)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-15058168)
 * I re-installed 2.5.5 and the error messages popped again. So back to 2.5.6-dev.
   Thanks!
 *  Plugin Author [Tim W](https://wordpress.org/support/users/timwhitlock/)
 * (@timwhitlock)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-15058189)
 * Thanks for the follow up.
 * As WordPress 5.8.2 has been released I will release 2.5.6 very soon.
 *  Thread Starter [ibrabulle](https://wordpress.org/support/users/ibrabulle/)
 * (@ibrabulle)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-15058807)
 * Great! Thanks for your support!

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Undefined array key “locales” – $Haystack’ is closed to new replies.

 * ![](https://ps.w.org/loco-translate/assets/icon-256x256.png?rev=1000676)
 * [Loco Translate](https://wordpress.org/plugins/loco-translate/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/loco-translate/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/loco-translate/)
 * [Active Topics](https://wordpress.org/support/plugin/loco-translate/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/loco-translate/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/loco-translate/reviews/)

## Tags

 * [warning](https://wordpress.org/support/topic-tag/warning/)

 * 11 replies
 * 2 participants
 * Last reply from: [ibrabulle](https://wordpress.org/support/users/ibrabulle/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/undefined-array-key-locales-haystack/#post-15058807)
 * Status: resolved