Problem:
The customer asked how the WordPress user "Language" field can be set through the Toolset's user form.
Solution:
Informed that there is no built-in method available in the Toolset Forms for this, so it will require some workaround and custom code.
WordPress store's the ISO language code for the user's selected WordPress admin language as a value, in the user meta field with key 'locale'.
In a user registration form, one can include a hidden generic field and fill its value with the language code of the current page's language. After that, the 'cred_save_data' hook can be used to programmatically set that selected language value into the user's 'locale' meta field:
add_action('cred_save_data', 'my_save_data_action',10,2); function my_save_data_action($user_id, $form_data) { // if a specific form if ($form_data['id']==1234) { update_user_meta( $user_id, 'locale', $_POST['locale'] ); } }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://developer.wordpress.org/reference/functions/update_user_meta/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Our next available supporter will start replying to tickets in about 1.67 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Karachi (GMT+05:00)