get_userdata() - WordPress 函数参考中文文档

返回介绍

get_userdata()

发布于 2017-09-10 字数8088 浏览 1198 评论 0

get_userdata( int $user_id )

Retrieve user info by user ID.


描述


参数

$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 );
}

更新日志

Version 描述
0.71 Introduced.

相关函数

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

上一篇:cache_users()

下一篇:calendar_week_mod()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!