get_userdata( int $user_id )
Retrieve user info by user ID.
Description #Description
Parameters #Parameters
- $user_id
-
(int) (Required) User ID
Return #Return
(WP_User|false) WP_User object on success, false on failure.
Source #Source
File: wp-includes/pluggable.php
function get_userdata( $user_id ) { return get_user_by( 'id', $user_id ); }
Expand full source code Collapse full source code View on Trac
Changelog #Changelog
Version | Description |
---|---|
0.71 | Introduced. |
Related #Related
Uses #Uses
Uses | Description |
---|---|
wp-includes/pluggable.php: get_user_by() |
Retrieve user info by a given field |
Used By #Used By
Used By | Description |
---|---|
wp-includes/class-wp-query.php: WP_Query::generate_postdata() |
Generate post data. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::get_lock_user_data() |
Get lock user data. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::get_user() |
Get the user, if the ID is valid. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::delete_item() |
Deletes a single user. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_database() |
Prepares a single post for create or update. |
wp-includes/embed.php: get_oembed_response_data() |
Retrieves the oEmbed response data for a given post. |
wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_title() |
Handles the title column output. |
wp-admin/includes/ajax-actions.php: wp_ajax_destroy_sessions() |
Ajax handler for destroying multiple open sessions for a user. |
wp-admin/includes/export.php: wxr_authors_list() |
Output list of authors with posts |
wp-admin/includes/deprecated.php: get_editable_user_ids() |
Gets the IDs of any users who can edit posts. |
wp-includes/capabilities.php: grant_super_admin() |
Grants Super Admin privileges. |
wp-includes/capabilities.php: revoke_super_admin() |
Revokes Super Admin privileges. |
wp-admin/includes/ms.php: refresh_user_details() |
Cleans the user cache for a specific user. |
wp-admin/includes/misc.php: wp_check_locked_posts() |
Check lock status for posts displayed on the Posts screen |
wp-admin/includes/misc.php: wp_refresh_post_lock() |
Check lock status on the New/Edit Post screen and refresh the lock |
wp-admin/includes/schema.php: populate_network() |
Populate network settings. |
wp-admin/includes/user.php: default_password_nag_edit_user() | |
wp-admin/includes/user.php: edit_user() |
Edit user settings based on contents of $_POST |
wp-admin/includes/user.php: get_user_to_edit() |
Retrieve user data and filter it. |
wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::single_row() |
Generate HTML for a single row on the users.php admin panel. |
wp-admin/includes/post.php: wp_check_post_lock() |
Check to see if the post is currently being edited by another user. |
wp-admin/includes/post.php: _admin_notice_post_locked() |
Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. |
wp-admin/includes/ajax-actions.php: wp_ajax_wp_fullscreen_save_post() |
Ajax handler for saving posts from the fullscreen editor. |
wp-admin/includes/ajax-actions.php: wp_ajax_add_user() |
Ajax handler for adding a user. |
wp-admin/includes/ajax-actions.php: wp_ajax_inline_save() |
Ajax handler for Quick Edit saving a post from a list table. |
wp-admin/includes/ms.php: confirm_delete_users() | |
wp-includes/capabilities.php: is_super_admin() |
Determine if user is a site admin. |
wp-includes/capabilities.php: author_can() |
Returns whether the author of the supplied post has the specified capability. |
wp-includes/capabilities.php: user_can() |
Returns whether a particular user has the specified capability. |
wp-includes/pluggable.php: wp_new_user_notification() |
Email login credentials to a newly-registered user. |
wp-includes/pluggable.php: wp_notify_postauthor() |
Notify an author (and/or others) of a comment/trackback/pingback on a post. |
wp-includes/pluggable.php: wp_notify_moderator() |
Notifies the moderator of the site about a new comment that is awaiting approval. |
wp-includes/pluggable.php: wp_generate_auth_cookie() |
Generates authentication cookie contents. |
wp-includes/deprecated.php: user_can_create_post() |
Whether user can create a post. |
wp-includes/deprecated.php: user_can_create_draft() |
Whether user can create a post. |
wp-includes/deprecated.php: user_can_edit_post() |
Whether user can edit a post. |
wp-includes/deprecated.php: user_can_set_post_date() |
Whether user can set new posts’ dates. |
wp-includes/deprecated.php: user_can_edit_post_date() |
Whether user can delete a post. |
wp-includes/deprecated.php: user_can_edit_user() |
Can user can edit other user. |
wp-includes/class-wp.php: WP::register_globals() |
Set up the WordPress Globals. |
wp-includes/class-wp-query.php: WP_Query::get_queried_object() |
Retrieve queried object. |
wp-includes/link-template.php: get_edit_user_link() |
Retrieves the edit user link. |
wp-includes/link-template.php: get_permalink() |
Retrieves the full permalink for the current post or post ID. |
wp-includes/admin-bar.php: wp_admin_bar_edit_menu() |
Provide an edit link for posts and terms. |
wp-includes/user.php: wp_update_user() |
Update a user in the database. |
wp-includes/user.php: wp_insert_user() |
Insert a user into the database. |
wp-includes/user.php: is_user_member_of_blog() |
Find out whether a user is a member of a given blog. |
wp-includes/user.php: setup_userdata() |
Set up global user vars. |
wp-includes/user.php: wp_dropdown_users() |
Create dropdown HTML content of users. |
wp-includes/user.php: get_user_option() |
Retrieve user option that can be either per Site or per Network. |
wp-includes/canonical.php: redirect_canonical() |
Redirects incoming links to the proper URL based on the site url. |
wp-includes/ms-functions.php: wpmu_welcome_user_notification() |
Notify a user that their account activation has been successful. |
wp-includes/ms-functions.php: wpmu_log_new_registrations() |
Logs the user email, IP, and registration date of a new site. |
wp-includes/ms-functions.php: newuser_notify_siteadmin() |
Notifies the network admin that a new user has been activated. |
wp-includes/ms-functions.php: wpmu_welcome_notification() |
Notify a user that their blog activation has been successful. |
wp-includes/ms-functions.php: add_user_to_blog() |
Adds a user to a blog. |
wp-includes/ms-functions.php: remove_user_from_blog() |
Remove a user from a blog. |
wp-includes/author-template.php: get_author_posts_url() |
Retrieve the URL to the author page for the user with the ID provided. |
wp-includes/author-template.php: wp_list_authors() |
List all the authors of the site, with several options available. |
wp-includes/author-template.php: get_the_author_meta() |
Retrieves the requested data of the author of the current post. |
wp-includes/author-template.php: get_the_modified_author() |
Retrieve the author who last edited the current post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_getPost() |
Retrieve post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_getRecentPosts() |
Retrieve list of recent posts. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_newPost() |
Create a new post. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getUser() |
Retrieve a user. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getProfile() |
Retrieve information about the requesting user. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_prepare_page() |
Prepares page data for return in an XML-RPC object. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_insert_post() |
Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
wp-includes/comment-template.php: get_comment_class() |
Returns the classes for the comment div as an array. |
wp-includes/comment-template.php: get_comment_author() |
Retrieve the author of the current comment. |
wp-includes/comment.php: wp_allow_comment() |
Validates whether this comment is allowed to be made. |
User Contributed Notes #User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Usage
The
get_userdata()
function returns an object of the user’s data. You can echo various parts of the returned object or loop through the data to display it all.Example displaying certain parts:
Results in:
Username: admin
User roles: administrator
User ID: 1
You can also assign certain parts into individual variables for displaying later or in multiple places.
Example for extracting certain parts:
Results in:
Harriet Smith logs into her WordPress site with the user name of mrssmith.
Accessing Usermeta Data
Results in:
Doe, John
Result : John, [email protected]