switch_to_user_locale()
Switches the translations according to the given user's locale.
No Hooks.
Returns
true|false. True on success, false on failure.
Usage
switch_to_user_locale( $user_id );
- $user_id(int) (required)
- User ID.
Notes
- Global. WP_Locale_Switcher.
$wp_locale_switcherWordPress locale switcher object.
Changelog
| Since 6.2.0 | Introduced. |
switch_to_user_locale() switch to user locale code WP 7.0
function switch_to_user_locale( $user_id ) {
/* @var WP_Locale_Switcher $wp_locale_switcher */
global $wp_locale_switcher;
if ( ! $wp_locale_switcher ) {
return false;
}
return $wp_locale_switcher->switch_to_user_locale( $user_id );
}