This thread is resolved. Here is a description of the problem and solution.
Problem:
The client needed to set up user locale (language) via an API for a WordPress site using WPML. They wanted to update the user's language preference, which is collected in an external system, to be used by a membership plugin for sending localized messages. The 'locale' field in the wp_usermeta table was not being updated when the language was switched using the language switcher, only when changed in the admin panel.
Solution:
We informed the client that the 'locale' field in the wp_usermeta table is not specific to WPML and is present even in a WordPress installation without WPML. This field is empty by default and only gets a value when the language is changed from 'Site default' to a specific language inside the user's WordPress profile.
To change the 'locale' value programmatically, we suggested looking at a Stack Overflow thread: https://stackoverflow.com/questions/8236280/setting-wordpress-language-programmatically.
We also clarified that WPML does not provide a hook to change the user language directly, but we do offer hooks that could be useful:
- To switch the language for emails: https://wpml.org/wpml-hook/wpml_switch_language_for_email/
- To set conditions and functions for the currently active language, which works for users on the frontend: https://wpml.org/wpml-hook/wpml_current_language/
If this solution is not relevant due to being outdated or not applicable to your case, we recommend opening a new support ticket. 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.
For further assistance, please contact us through the WPML support forum: https://wpml.org/forums/forum/english-support/.
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.
This topic contains 3 replies, has 2 voices.
Last updated by 1 year, 2 months ago.
Assisted by: Andreas W..