get_user_locale
Retrieves the locale of a user.
Description
(string) get_user_locale( (int) $user_id = 0 );
If the user has a locale set to a non-empty string then it will be returned. Otherwise it returns the locale of get_locale(…)
.
Returns (string)
The locale of the user.
Parameters (1)
- 0. $user_id — Optional. (int)
- User's ID or a
WP_User
object. Defaults to current user.
Usage
if ( !function_exists( 'get_user_locale' ) ) { require_once ABSPATH . WPINC . '/l10n.php'; } // User's ID or a WP_User object. Defaults to current user. $user_id = -1; // NOTICE! Understand what this does before running. $result = get_user_locale($user_id);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/l10n.php
- function get_user_locale( $user_id = 0 ) {
- $user = false;
- if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
- $user = wp_get_current_user();
- } elseif ( $user_id instanceof WP_User ) {
- $user = $user_id;
- } elseif ( $user_id && is_numeric( $user_id ) ) {
- $user = get_user_by( 'id', $user_id );
- }
- if ( ! $user ) {
- return get_locale();
- }
- $locale = $user->locale;
- return $locale ? $locale : get_locale();
- }