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

  1. if ( !function_exists( 'get_user_locale' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // User's ID or a WP_User object. Defaults to current user. 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_user_locale($user_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/l10n.php  
  1. function get_user_locale( $user_id = 0 ) { 
  2. $user = false; 
  3. if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) { 
  4. $user = wp_get_current_user(); 
  5. } elseif ( $user_id instanceof WP_User ) { 
  6. $user = $user_id; 
  7. } elseif ( $user_id && is_numeric( $user_id ) ) { 
  8. $user = get_user_by( 'id', $user_id ); 
  9.  
  10. if ( ! $user ) { 
  11. return get_locale(); 
  12.  
  13. $locale = $user->locale; 
  14. return $locale ? $locale : get_locale();