Retrieves the current user object.
Description
Will set the current user, if the current user is not set. The current user will be set to the logged-in person. If no user is logged-in, then it will set the current user to 0, which is invalid and won’t have any permissions.
See also
Return
WP_User Current WP_User instance.Source
function wp_get_current_user() {
return _wp_get_current_user();
}
Related
Uses | Description |
---|---|
_wp_get_current_user()wp-includes/user.php | Retrieves the current user object. |
Used by | Description |
---|---|
WP_REST_Application_Passwords_Controller::get_user()wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php | Gets the requested user. |
populate_network_meta()wp-admin/includes/schema.php | Creates WordPress network meta and sets the default values. |
the_block_editor_meta_box_post_form_hidden_fields()wp-admin/includes/post.php | Renders the hidden form required for the meta boxes form. |
wp_enqueue_code_editor()wp-includes/general-template.php | Enqueues assets needed by the code editor for the given settings. |
wp_switch_roles_and_user()wp-includes/ms-blogs.php | Switches the initialized roles and current user capabilities to another site. |
WP_Widget_Custom_HTML::add_help_text()wp-includes/widgets/class-wp-widget-custom-html.php | Add help text to widgets admin screen. |
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. |
get_user_locale()wp-includes/l10n.php | Retrieves the locale of a user. |
WP_REST_Users_Controller::get_current_item()wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php | Retrieves the current user. |
WP_REST_Comments_Controller::create_item()wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Creates a comment. |
wp_handle_comment_submission()wp-includes/comment.php | Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form. |
WP_Screen::render_meta_boxes_preferences()wp-admin/includes/class-wp-screen.php | Renders the meta boxes preferences. |
signup_another_blog()wp-signup.php | Shows a form for returning users to sign up for another site. |
validate_another_blog_signup()wp-signup.php | Validates a new site sign-up for an existing user. |
validate_blog_form()wp-signup.php | Validates the new site sign-up. |
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. |
send_confirmation_on_profile_email()wp-includes/user.php | Sends a confirmation request email when a change of user email address is attempted. |
set_screen_options()wp-admin/includes/misc.php | Saves option for number of rows when listing posts, pages, comments, etc. |
wp_ajax_closed_postboxes()wp-admin/includes/ajax-actions.php | Handles closed post boxes via AJAX. |
wp_ajax_hidden_columns()wp-admin/includes/ajax-actions.php | Handles hidden columns via AJAX. |
wp_ajax_meta_box_order()wp-admin/includes/ajax-actions.php | Handles saving the meta box order via AJAX. |
wp_ajax_replyto_comment()wp-admin/includes/ajax-actions.php | Handles replying to a comment via AJAX. |
wp_nav_menu_setup()wp-admin/includes/nav-menu.php | Register nav menu meta boxes and advanced menu items. |
wp_initial_nav_menu_meta_boxes()wp-admin/includes/nav-menu.php | Limit the amount of meta boxes to pages, posts, links, and categories for first time users. |
confirm_delete_users()wp-admin/includes/ms.php | |
current_user_can()wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
is_super_admin()wp-includes/capabilities.php | Determines whether user is a site admin. |
WP_Customize_Manager::register_controls()wp-includes/class-wp-customize-manager.php | Registers some default controls. |
wp_verify_nonce()wp-includes/pluggable.php | Verifies that a correct security nonce was used with time limit. |
wp_create_nonce()wp-includes/pluggable.php | Creates a cryptographic token tied to a specific action, user, user session, and window of time. |
is_user_logged_in()wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. |
wp_default_editor()wp-includes/general-template.php | Finds out which editor should be displayed by default. |
WP::init()wp-includes/class-wp.php | Set up the current user. |
wp_admin_bar_my_account_item()wp-includes/admin-bar.php | Adds the “My Account” item. |
wp_admin_bar_my_account_menu()wp-includes/admin-bar.php | Adds the “My Account” submenu items. |
wp_update_user()wp-includes/user.php | Updates a user in the database. |
get_current_user_id()wp-includes/user.php | Gets the current user’s ID. |
is_user_option_local()wp-includes/ms-deprecated.php | Check whether a usermeta key has to do with the current blog. |
is_user_spammy()wp-includes/ms-functions.php | Determines whether a user is marked as a spammer, based on user login. |
comment_form()wp-includes/comment-template.php | Outputs a complete commenting form for use within a template. |
Changelog
Version | Description |
---|---|
2.0.3 | Introduced. |
Default Usage
The call to
wp_get_current_user()
returns the WP_User object.Just want the ID (and nothing else)?
Just use get_current_user_id() instead:
You can use it from the plugins_loaded hook on.
Checking User Role
This example demonstrates how to find if the user is an admin.
Checking Other User Attributes
This example demonstrates how to manually determine if a user is logged in.
IMPORTANT NOTE: This is for demonstration purposes ONLY. The correct way to determine whether a user is logged in is to use the function
is_user_logged_in()
.