返回介绍

get_userdata()

发布于 2017-09-10 21:36:41 字数 8086 浏览 1419 评论 0 收藏 0

get_userdata( int $user_id )

Retrieve user info by user ID.


description


参数

$user_id

(int) (Required) User ID


返回值

(WP_User|false) WP_User object on success, false on failure.


源代码

File: wp-includes/pluggable.php

function get_userdata( $user_id ) {
	return get_user_by( 'id', $user_id );
}

更新日志

Versiondescription
0.71Introduced.

相关函数

Uses

  • wp-includes/pluggable.php: get_user_by()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::get_user()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::delete_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::prepare_item_for_database()
  • wp-includes/embed.php: get_oembed_response_data()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_title()
  • wp-includes/class-wp-query.php: WP_Query::setup_postdata()
  • wp-admin/includes/ajax-actions.php: wp_ajax_destroy_sessions()
  • wp-admin/includes/export.php: wxr_authors_list()
  • wp-admin/includes/deprecated.php: get_editable_user_ids()
  • wp-includes/capabilities.php: grant_super_admin()
  • wp-includes/capabilities.php: revoke_super_admin()
  • wp-admin/includes/ms.php: refresh_user_details()
  • wp-admin/includes/misc.php: wp_check_locked_posts()
  • wp-admin/includes/misc.php: wp_refresh_post_lock()
  • wp-admin/includes/user.php: default_password_nag_edit_user()
  • wp-admin/includes/user.php: edit_user()
  • wp-admin/includes/user.php: get_user_to_edit()
  • wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::single_row()
  • wp-admin/includes/post.php: wp_check_post_lock()
  • wp-admin/includes/post.php: _admin_notice_post_locked()
  • wp-admin/includes/ajax-actions.php: wp_ajax_wp_fullscreen_save_post()
  • wp-admin/includes/ajax-actions.php: wp_ajax_add_user()
  • wp-admin/includes/ajax-actions.php: wp_ajax_inline_save()
  • wp-admin/includes/ms.php: confirm_delete_users()
  • wp-includes/capabilities.php: author_can()
  • wp-includes/capabilities.php: user_can()
  • wp-includes/capabilities.php: is_super_admin()
  • wp-includes/pluggable.php: wp_new_user_notification()
  • wp-includes/pluggable.php: wp_notify_postauthor()
  • wp-includes/pluggable.php: wp_notify_moderator()
  • wp-includes/pluggable.php: wp_generate_auth_cookie()
  • wp-includes/deprecated.php: user_can_create_post()
  • wp-includes/deprecated.php: user_can_create_draft()
  • wp-includes/deprecated.php: user_can_edit_post()
  • wp-includes/deprecated.php: user_can_set_post_date()
  • wp-includes/deprecated.php: user_can_edit_post_date()
  • wp-includes/deprecated.php: user_can_edit_user()
  • wp-includes/class-wp.php: WP::register_globals()
  • wp-includes/class-wp-query.php: WP_Query::get_queried_object()
  • wp-includes/link-template.php: get_edit_user_link()
  • wp-includes/link-template.php: get_permalink()
  • wp-includes/user.php: wp_update_user()
  • wp-includes/user.php: check_password_reset_key()
  • wp-includes/user.php: wp_insert_user()
  • wp-includes/user.php: is_user_member_of_blog()
  • wp-includes/user.php: setup_userdata()
  • wp-includes/user.php: wp_dropdown_users()
  • wp-includes/user.php: get_user_option()
  • wp-includes/canonical.php: redirect_canonical()
  • wp-includes/ms-functions.php: wpmu_welcome_user_notification()
  • wp-includes/ms-functions.php: wpmu_log_new_registrations()
  • wp-includes/ms-functions.php: newuser_notify_siteadmin()
  • wp-includes/ms-functions.php: wpmu_welcome_notification()
  • wp-includes/ms-functions.php: add_user_to_blog()
  • wp-includes/ms-functions.php: remove_user_from_blog()
  • wp-includes/author-template.php: get_the_author_meta()
  • wp-includes/author-template.php: get_author_posts_url()
  • wp-includes/author-template.php: wp_list_authors()
  • wp-includes/author-template.php: get_the_modified_author()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_getPost()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_getRecentPosts()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::mw_newPost()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getUser()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getProfile()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_prepare_page()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_insert_post()
  • wp-includes/comment-template.php: get_comment_class()
  • wp-includes/comment-template.php: get_comment_author()
  • wp-includes/comment.php: wp_allow_comment()
  • Show 64 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note Contributed by Codex

    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:

    
    <?php $user_info = get_userdata(1);
          echo 'Username: ' . $user_info->user_login . "\n";
          echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
          echo 'User ID: ' . $user_info->ID . "\n";
    ?>
    

    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:

    
    <?php $user_info = get_userdata(1);
          $username = $user_info->user_login;
          $first_name = $user_info->first_name;
          $last_name = $user_info->last_name;
          echo "$first_name $last_name logs into her WordPress site with the user name of $username.";
    ?>
    

    Results in:

    Harriet Smith logs into her WordPress site with the user name of mrssmith.

  2. Accessing Usermeta Data

    
    <?php $user_info = get_userdata(1);
          echo $user_info->last_name .  ", " . $user_info->first_name . "\n";
    ?>
    

    Results in:

    Doe, John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文