On this page
get_user_locale( int|WP_User $user ): string
Retrieves the locale of a user.
Description
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() .
Parameters
Return
string The locale of the user.
Source
File: wp-includes/l10n.php. View all references
function get_user_locale( $user = 0 ) {
$user_object = false;
if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) {
$user_object = wp_get_current_user();
} elseif ( $user instanceof WP_User ) {
$user_object = $user;
} elseif ( $user && is_numeric( $user ) ) {
$user_object = get_user_by( 'id', $user );
}
if ( ! $user_object ) {
return get_locale();
}
$locale = $user_object->locale;
return $locale ? $locale : get_locale();
}
Related
Uses
| Uses | Description |
|---|---|
| get_locale() wp-includes/l10n.php | Retrieves the current locale. |
| wp_get_current_user() wp-includes/pluggable.php | Retrieves the current user object. |
| get_user_by() wp-includes/pluggable.php | Retrieves user info by a given field. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Pattern_Directory_Controller::get_items() wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php | Search and retrieve block patterns metadata |
| wpmu_new_site_admin_notification() wp-includes/ms-functions.php | Notifies the Multisite network administrator that a new site was created. |
| WP_Debug_Data::debug_data() wp-admin/includes/class-wp-debug-data.php | Static function for generating site debug data when required. |
| determine_locale() wp-includes/l10n.php | Determines the current locale desired for the request. |
| wp_default_packages_vendor() wp-includes/script-loader.php | Registers all the WordPress vendor scripts that are in the standardized |
| wp_default_packages_inline_scripts() wp-includes/script-loader.php | Adds inline scripts required for the WordPress JavaScript packages. |
| _wp_privacy_send_erasure_fulfillment_notification() wp-includes/user.php | Notifies the user when their erasure request is fulfilled. |
| wp_send_user_request() wp-includes/user.php | Send a confirmation request email to confirm an action. |
| wp_privacy_send_personal_data_export_email() wp-admin/includes/privacy-tools.php | Send an email to the user with a link to the personal data export file |
| update_network_option_new_admin_email() wp-includes/ms-functions.php | Sends a confirmation request email when a change of network admin email address is attempted. |
| _WP_Editors::get_mce_locale() wp-includes/class-wp-editor.php | Returns the TinyMCE locale. |
| WP_Community_Events::get_request_args() wp-admin/includes/class-wp-community-events.php | Builds an array of args to use in an HTTP request to the w.org Events API. |
| WP_REST_Users_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php | Prepares a single user output for response. |
| WP_Customize_Selective_Refresh::export_preview_data() wp-includes/customize/class-wp-customize-selective-refresh.php | Exports data in preview after it has finished rendering so that partials can be added at runtime. |
| retrieve_password() wp-includes/user.php | Handles sending a password retrieval email to a user. |
| themes_api() wp-admin/includes/theme.php | Retrieves theme installer pages from the WordPress.org Themes API. |
| update_option_new_admin_email() wp-admin/includes/misc.php | Sends a confirmation request email when a change of site admin email address is attempted. |
| plugins_api() wp-admin/includes/plugin-install.php | Retrieves plugin installer pages from the WordPress.org Plugins API. |
| wp_dashboard_cached_rss_widget() wp-admin/includes/dashboard.php | Checks to see if all of the feed url in $check_urls are cached. |
| wp_dashboard_rss_control() wp-admin/includes/dashboard.php | The RSS dashboard widget control. |
| wp_dashboard_browser_nag() wp-admin/includes/dashboard.php | Displays the browser update nag. |
| WP_Plugin_Install_List_Table::prepare_items() wp-admin/includes/class-wp-plugin-install-list-table.php | |
| iframe_header() wp-admin/includes/template.php | Generic Iframe header for use with Thickbox. |
| wp_get_popular_importers() wp-admin/includes/import.php | Returns a list from WordPress.org of popular importer plugins. |
| wp_credits() wp-admin/includes/credits.php | Retrieve the contributor credits. |
| WP_Customize_Manager::customize_preview_settings() wp-includes/class-wp-customize-manager.php | Prints JavaScript settings for preview frame. |
| wp_new_user_notification() wp-includes/pluggable.php | Emails login credentials to a newly-registered user. |
| WP_Theme::sort_by_name() wp-includes/class-wp-theme.php | Sorts themes by name. |
| wp_auth_check_html() wp-includes/functions.php | Outputs the HTML that shows the wp-login dialog when the user is no longer logged in. |
| wp_update_user() wp-includes/user.php | Updates a user in the database. |
| wpmu_welcome_user_notification() wp-includes/ms-functions.php | Notifies a user that their account activation has been successful. |
| wpmu_welcome_notification() wp-includes/ms-functions.php | Notifies the site administrator that their site activation was successful. |
| wpmu_signup_blog_notification() wp-includes/ms-functions.php | Sends a confirmation request email to a user when they sign up for a new site. The new site will not become active until the confirmation link is clicked. |
| wpmu_signup_user_notification() wp-includes/ms-functions.php | Sends a confirmation request email to a user when they sign up for a new user account (without signing up for a site at the same time). The user account will not become active until the confirmation link is clicked. |
| WP_Customize_Widgets::export_preview_data() wp-includes/class-wp-customize-widgets.php | Communicates the sidebars that appeared on the page at the very end of the page, and at the very end of the wp_footer, |
| _WP_Editors::editor_settings() wp-includes/class-wp-editor.php |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_user_locale