1

Anyone know how to change a specific user language when they switch WPML language?

For Example the steps:

  1. The website default language is English.
  2. After admin create new user (User1), their default language when login is English (EN).
  3. User1 login.
  4. User1 use switching bar on the top to change the language from EN to DE.
  5. User1 logout.
  6. User1 login in the next time, the language is EN.

Expect result in step 6: the language should be DE.

I want to change the user language programmatically because the user not have permission to access their profile page.

Any ideas please?

Mít
  • 195
  • 1
  • 3
  • 18

1 Answers1

0

You can store the user preferred language in the database, then fetch that with get_user_option, compare to current language, and redirect to their preferred if it's not matching. For example (untested):

$user_lang = get_user_option( 'user_lang_pref', get_current_user_id() );

$current_lang = apply_filters( 'wpml_current_language', NULL );

if($user_lang != $current_lang) {
    // redirect to /wp-admin/index.php?lang=[USER_LANG]&admin_bar=1
}

Here's the WPML hook documentation: wpml_current_language

montrealist
  • 5,593
  • 12
  • 46
  • 68