switch_to_user_locale

The timeline below displays how wordpress function switch_to_user_locale has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Switches the translations according to the given user's locale.
 *
 * @since 6.2.0
 *
 * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object.
 *
 * @param int $user_id User ID.
 * @return bool True on success, false on failure.
 */
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);
}