wp_get_current_user()
Retrieve the current user object.
Description #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 #See also
Return #Return
Source #Source
File: wp-includes/pluggable.php
function wp_get_current_user() { return _wp_get_current_user(); }
Expand full source code Collapse full source code View on Trac
Changelog #Changelog
Version | Description |
---|---|
2.0.3 | Introduced. |
Related #Related
Uses #Uses
Uses | Description |
---|---|
wp-includes/user.php: _wp_get_current_user() |
Retrieves the current user object. |
Used By #Used By
Used By | Description |
---|---|
wp-admin/includes/schema.php: populate_network_meta() |
Creates WordPress network meta and sets the default values. |
wp-admin/includes/post.php: the_block_editor_meta_box_post_form_hidden_fields() |
Renders the hidden form required for the meta boxes form. |
wp-includes/general-template.php: wp_enqueue_code_editor() |
Enqueue assets needed by the code editor for the given settings. |
wp-includes/ms-blogs.php: wp_switch_roles_and_user() |
Switches the initialized roles and current user capabilities to another site. |
wp-includes/widgets/class-wp-widget-custom-html.php: WP_Widget_Custom_HTML::add_help_text() |
Add help text to widgets admin screen. |
wp-includes/ms-functions.php: update_network_option_new_admin_email() |
Send a confirmation request email when a change of network admin email address is attempted. |
wp-includes/l10n.php: get_user_locale() |
Retrieves the locale of a user. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::get_current_item() |
Retrieves the current user. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item() |
Creates a comment. |
wp-includes/comment.php: wp_handle_comment_submission() |
Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form. |
wp-admin/includes/class-wp-screen.php: WP_Screen::render_meta_boxes_preferences() |
Render the meta boxes preferences. |
wp-signup.php: signup_another_blog() |
Allow returning users to sign up for another site |
wp-signup.php: validate_another_blog_signup() |
Validate a new site signup for an existing user. |
wp-signup.php: validate_blog_form() |
Validate the new site signup |
wp-admin/includes/misc.php: update_option_new_admin_email() |
Send a confirmation request email when a change of site admin email address is attempted. |
wp-includes/user.php: send_confirmation_on_profile_email() |
Send a confirmation request email when a change of user email address is attempted. |
wp-admin/includes/misc.php: set_screen_options() |
Saves option for number of rows when listing posts, pages, comments, etc. |
wp-admin/includes/ajax-actions.php: wp_ajax_closed_postboxes() |
Ajax handler for closed post boxes. |
wp-admin/includes/ajax-actions.php: wp_ajax_hidden_columns() |
Ajax handler for hidden columns. |
wp-admin/includes/ajax-actions.php: wp_ajax_meta_box_order() |
Ajax handler for saving the meta box order. |
wp-admin/includes/ajax-actions.php: wp_ajax_replyto_comment() |
Ajax handler for replying to a comment. |
wp-admin/includes/nav-menu.php: wp_nav_menu_setup() |
Register nav menu meta boxes and advanced menu items. |
wp-admin/includes/nav-menu.php: wp_initial_nav_menu_meta_boxes() |
Limit the amount of meta boxes to pages, posts, links, and categories for first time users. |
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: current_user_can() |
Returns whether the current user has the specified capability. |
wp-includes/capabilities.php: current_user_can_for_blog() |
Returns whether the current user has the specified capability for a given site. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::register_controls() |
Register some default controls. |
wp-includes/pluggable.php: wp_verify_nonce() |
Verifies that a correct security nonce was used with time limit. |
wp-includes/pluggable.php: wp_create_nonce() |
Creates a cryptographic token tied to a specific action, user, user session, and window of time. |
wp-includes/pluggable.php: is_user_logged_in() |
Determines whether the current visitor is a logged in user. |
wp-includes/general-template.php: wp_default_editor() |
Find out which editor should be displayed by default. |
wp-includes/class-wp.php: WP::init() |
Set up the current user. |
wp-includes/admin-bar.php: wp_admin_bar_my_account_item() |
Add the “My Account” item. |
wp-includes/admin-bar.php: wp_admin_bar_my_account_menu() |
Add the “My Account” submenu items. |
wp-includes/user.php: wp_update_user() |
Update a user in the database. |
wp-includes/user.php: get_current_user_id() |
Get the current user’s ID |
wp-includes/ms-deprecated.php: is_user_option_local() |
Check whether a usermeta key has to do with the current blog. |
wp-includes/ms-functions.php: is_user_spammy() |
Check to see whether a user is marked as a spammer, based on user login. |
wp-includes/comment-template.php: comment_form() |
Outputs a complete commenting form for use within a template. |
User Contributed Notes #User Contributed Notes
You must log in before being able to contribute a note or feedback.
Default Usage
The call to
wp_get_current_user()
returns the WP_User object.Expand full source codeCollapse full source code
You can use it from the plugins_loaded hook on.
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()
.