^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_current_user_id()用法示例

get_current_user_id()

Get the current user’s ID


描述


返回值

(int) The current user’s ID, or 0 if no user is logged in.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


源代码

File: wp-includes/user.php

function get_current_user_id() {
	if ( ! function_exists( 'wp_get_current_user' ) )
		return 0;
	$user = wp_get_current_user();
	return ( isset( $user->ID ) ? (int) $user->ID : 0 );
}

更新日志

Version 描述
MU Introduced.

相关函数

Uses

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

Used By

  • wp-includes/script-loader.php:
    wp_localize_community_events()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_get_community_events()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::_publish_changeset_values()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::save_changeset_post()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:
    WP_REST_Users_Controller::delete_current_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:
    WP_REST_Users_Controller::check_role_update()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:
    WP_REST_Users_Controller::update_current_item_permissions_check()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:
    WP_REST_Users_Controller::update_current_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:
    WP_REST_Users_Controller::delete_current_item_permissions_check()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:
    WP_REST_Users_Controller::get_current_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:
    WP_REST_Users_Controller::get_item_permissions_check()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::prepare_item_for_database()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::update_item_permissions_check()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::create_item_permissions_check()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::check_edit_permission()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::check_read_permission()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::create_item_permissions_check()
  • wp-includes/comment.php:
    wp_check_comment_flood()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_meta_boxes_preferences()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_save_wporg_username()
  • wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:
    WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_destroy_sessions()
  • wp-includes/user.php:
    wp_destroy_all_sessions()
  • wp-includes/user.php:
    wp_get_all_sessions()
  • wp-includes/user.php:
    wp_destroy_current_session()
  • wp-includes/user.php:
    wp_destroy_other_sessions()
  • wp-admin/includes/ms.php:
    _access_denied_splash()
  • wp-admin/includes/ms.php:
    choose_primary_blog()
  • wp-admin/includes/ms.php:
    new_user_email_admin_notice()
  • wp-admin/includes/plugin-install.php:
    install_plugins_favorites_form()
  • wp-admin/includes/dashboard.php:
    wp_dashboard_quick_press()
  • wp-admin/includes/dashboard.php:
    wp_dashboard_recent_drafts()
  • wp-admin/includes/user.php:
    edit_user()
  • wp-admin/includes/class-wp-plugin-install-list-table.php:
    WP_Plugin_Install_List_Table::prepare_items()
  • wp-admin/includes/class-wp-internal-pointers.php:
    WP_Internal_Pointers::enqueue_scripts()
  • 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:
    wp_set_post_lock()
  • wp-admin/includes/post.php:
    wp_create_post_autosave()
  • wp-admin/includes/post.php:
    post_preview()
  • wp-admin/includes/post.php:
    wp_autosave()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_save_user_color_scheme()
  • wp-admin/includes/post.php:
    _wp_translate_postdata()
  • wp-admin/includes/post.php:
    edit_post()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_wp_remove_post_lock()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_dismiss_wp_pointer()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_update_welcome_panel()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_inline_save()
  • wp-admin/includes/bookmark.php:
    wp_insert_link()
  • wp-admin/includes/class-wp-media-list-table.php:
    WP_Media_List_Table::display_rows()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::single_row()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::get_views()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::__construct()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::prepare_items()
  • wp-includes/capabilities.php:
    is_super_admin()
  • wp-includes/pluggable.php:
    wp_notify_postauthor()
  • wp-includes/pluggable.php:
    wp_clear_auth_cookie()
  • wp-includes/deprecated.php:
    wp_admin_bar_dashboard_view_site_menu()
  • wp-includes/deprecated.php:
    is_blog_user()
  • wp-includes/class-wp-query.php:
    WP_Query::get_posts()
  • wp-includes/link-template.php:
    get_dashboard_url()
  • wp-includes/link-template.php:
    get_edit_profile_url()
  • wp-includes/link-template.php:
    get_edit_user_link()
  • wp-includes/link-template.php:
    get_adjacent_post()
  • wp-includes/class-wp-admin-bar.php:
    WP_Admin_Bar::initialize()
  • wp-includes/admin-bar.php:
    wp_admin_bar_wp_menu()
  • wp-includes/admin-bar.php:
    wp_admin_bar_my_account_item()
  • wp-includes/admin-bar.php:
    wp_admin_bar_my_account_menu()
  • wp-includes/option.php:
    wp_user_settings()
  • wp-includes/option.php:
    get_all_user_settings()
  • wp-includes/option.php:
    wp_set_all_user_settings()
  • wp-includes/option.php:
    delete_all_user_settings()
  • wp-includes/user.php:
    is_user_member_of_blog()
  • wp-includes/user.php:
    setup_userdata()
  • wp-includes/user.php:
    get_user_option()
  • wp-includes/post.php:
    get_posts_by_author_sql()
  • wp-includes/post.php:
    wp_insert_post()
  • wp-includes/post.php:
    _count_posts_cache_key()
  • wp-includes/post.php:
    wp_count_posts()
  • wp-includes/revision.php:
    wp_restore_post_revision()
  • wp-includes/ms-deprecated.php:
    is_site_admin()
  • wp-includes/comment-template.php:
    wp_list_comments()
  • wp-includes/script-loader.php:
    wp_default_scripts()
  • Show 78 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 6You must log in to vote on the helpfulness of this note

    Contributed by SoN9ne

    daniyalahmedk’s example is redundant.

    The code below is the exact same thing but with less overhead.

    Get current user role by ID :

    
    $user = wp_get_current_user();
    echo $user->roles[0];
    

    There is no need to invoke a new WP_User object.

  2. Get current user role by ID :

    $user = new WP_User(get_current_user_id());
    echo $user->roles[0];

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈