Title: wp_get_current_user
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_get_current_user(): 󠀁[WP_User](https://developer.wordpress.org/reference/classes/wp_user/)󠁿

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#see-also)
 * [Return](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#user-contributed-notes)

Retrieves the current user object.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#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](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#see-also)󠁿

 * [_wp_get_current_user()](https://developer.wordpress.org/reference/functions/_wp_get_current_user/)

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#return)󠁿

 [WP_User](https://developer.wordpress.org/reference/classes/wp_user/) Current [WP_User](https://developer.wordpress.org/reference/classes/wp_user/)
instance.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#source)󠁿

    ```php
    function wp_get_current_user() {
    	return _wp_get_current_user();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/pluggable.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/pluggable.php#L69)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/pluggable.php#L69-L71)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#related)󠁿

| Uses | Description | 
| [_wp_get_current_user()](https://developer.wordpress.org/reference/functions/_wp_get_current_user/)`wp-includes/user.php` |

Retrieves the current user object.

  |

| Used by | Description | 
| [wp_register_core_abilities()](https://developer.wordpress.org/reference/functions/wp_register_core_abilities/)`wp-includes/abilities.php` |

Registers the default core abilities.

  | 
| [WP_REST_Application_Passwords_Controller::get_user()](https://developer.wordpress.org/reference/classes/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()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/classes/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()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/get_user_locale/)`wp-includes/l10n.php` |

Retrieves the locale of a user.

  | 
| [WP_REST_Users_Controller::get_current_item()](https://developer.wordpress.org/reference/classes/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()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Creates a comment.

  | 
| [wp_handle_comment_submission()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/classes/wp_screen/render_meta_boxes_preferences/)`wp-admin/includes/class-wp-screen.php` |

Renders the meta boxes preferences.

  | 
| [signup_another_blog()](https://developer.wordpress.org/reference/functions/signup_another_blog/)`wp-signup.php` |

Shows a form for returning users to sign up for another site.

  | 
| [validate_another_blog_signup()](https://developer.wordpress.org/reference/functions/validate_another_blog_signup/)`wp-signup.php` |

Validates a new site sign-up for an existing user.

  | 
| [validate_blog_form()](https://developer.wordpress.org/reference/functions/validate_blog_form/)`wp-signup.php` |

Validates the new site sign-up.

  | 
| [update_option_new_admin_email()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/set_screen_options/)`wp-admin/includes/misc.php` |

Saves option for number of rows when listing posts, pages, comments, etc.

  | 
| [wp_ajax_closed_postboxes()](https://developer.wordpress.org/reference/functions/wp_ajax_closed_postboxes/)`wp-admin/includes/ajax-actions.php` |

Handles closed post boxes via AJAX.

  | 
| [wp_ajax_hidden_columns()](https://developer.wordpress.org/reference/functions/wp_ajax_hidden_columns/)`wp-admin/includes/ajax-actions.php` |

Handles hidden columns via AJAX.

  | 
| [wp_ajax_meta_box_order()](https://developer.wordpress.org/reference/functions/wp_ajax_meta_box_order/)`wp-admin/includes/ajax-actions.php` |

Handles saving the meta box order via AJAX.

  | 
| [wp_ajax_replyto_comment()](https://developer.wordpress.org/reference/functions/wp_ajax_replyto_comment/)`wp-admin/includes/ajax-actions.php` |

Handles replying to a comment via AJAX.

  | 
| [wp_nav_menu_setup()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/confirm_delete_users/)`wp-admin/includes/ms.php` |  | 
| [is_super_admin()](https://developer.wordpress.org/reference/functions/is_super_admin/)`wp-includes/capabilities.php` |

Determines whether user is a site admin.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [WP_Customize_Manager::register_controls()](https://developer.wordpress.org/reference/classes/wp_customize_manager/register_controls/)`wp-includes/class-wp-customize-manager.php` |

Registers some default controls.

  | 
| [wp_verify_nonce()](https://developer.wordpress.org/reference/functions/wp_verify_nonce/)`wp-includes/pluggable.php` |

Verifies that a correct security nonce was used with time limit.

  | 
| [wp_create_nonce()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/is_user_logged_in/)`wp-includes/pluggable.php` |

Determines whether the current visitor is a logged in user.

  | 
| [wp_default_editor()](https://developer.wordpress.org/reference/functions/wp_default_editor/)`wp-includes/general-template.php` |

Finds out which editor should be displayed by default.

  | 
| [WP::init()](https://developer.wordpress.org/reference/classes/wp/init/)`wp-includes/class-wp.php` |

Set up the current user.

  | 
| [wp_admin_bar_my_account_item()](https://developer.wordpress.org/reference/functions/wp_admin_bar_my_account_item/)`wp-includes/admin-bar.php` |

Adds the “My Account” item.

  | 
| [wp_admin_bar_my_account_menu()](https://developer.wordpress.org/reference/functions/wp_admin_bar_my_account_menu/)`wp-includes/admin-bar.php` |

Adds the “My Account” submenu items.

  | 
| [wp_update_user()](https://developer.wordpress.org/reference/functions/wp_update_user/)`wp-includes/user.php` |

Updates a user in the database.

  | 
| [get_current_user_id()](https://developer.wordpress.org/reference/functions/get_current_user_id/)`wp-includes/user.php` |

Gets the current user’s ID.

  | 
| [is_user_option_local()](https://developer.wordpress.org/reference/functions/is_user_option_local/)`wp-includes/ms-deprecated.php` |

Check whether a usermeta key has to do with the current blog.

  | 
| [is_user_spammy()](https://developer.wordpress.org/reference/functions/is_user_spammy/)`wp-includes/ms-functions.php` |

Determines whether a user is marked as a spammer, based on user login.

  | 
| [comment_form()](https://developer.wordpress.org/reference/functions/comment_form/)`wp-includes/comment-template.php` |

Outputs a complete commenting form for use within a template.

  |

[Show 36 more](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.3](https://developer.wordpress.org/reference/since/2.0.3/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#comment-content-437)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_current_user/#comment-437)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-437)
     Vote results for this note: 18[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-437)
 4.  **Default Usage**
      The call to `wp_get_current_user()` returns the [WP_User](https://developer.wordpress.org/reference/classes/wp_user/)
     object.
 5.      ```php
         <?php
         $current_user = wp_get_current_user();
     
         /*
          * @example Safe usage: $current_user = wp_get_current_user();
          * if ( ! ( $current_user instanceof WP_User ) ) {
          *     return;
          * }
          */
         printf( __( 'Username: %s', 'textdomain' ), esc_html( $current_user->user_login ) ) . '<br />';
         printf( __( 'User email: %s', 'textdomain' ), esc_html( $current_user->user_email ) ) . '<br />';
         printf( __( 'User first name: %s', 'textdomain' ), esc_html( $current_user->user_firstname ) ) . '<br />';
         printf( __( 'User last name: %s', 'textdomain' ), esc_html( $current_user->user_lastname ) ) . '<br />';
         printf( __( 'User display name: %s', 'textdomain' ), esc_html( $current_user->display_name ) ) . '<br />';
         printf( __( 'User ID: %s', 'textdomain' ), esc_html( $current_user->ID ) );
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%3Freplytocom%3D437%23feedback-editor-437)
 7.   [Skip to note 7 content](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#comment-content-4578)
 8.    [rmdundon](https://profiles.wordpress.org/rmdundon/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_current_user/#comment-4578)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-4578)
     Vote results for this note: 7[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-4578)
 10. Just want the ID (and nothing else)?
 11. Just use [get_current_user_id()](https://developer.wordpress.org/reference/functions/get_current_user_id)
     instead:
 12.     ```php
            $current_user_id = get_current_user_id();
            $current_user = wp_get_current_user();
         ```
     
 13.  * When using this in the constructor of a class I found this function gave an
        error. Turned out it was this point, I didn’t wait till plugins loaded. Good
        point.
      * [spinozarabel](https://profiles.wordpress.org/spinozarabel/) [5 years ago](https://developer.wordpress.org/reference/functions/wp_get_current_user/#comment-5172)
 14.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%3Freplytocom%3D4578%23feedback-editor-4578)
 15.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#comment-content-2506)
 16.   [marale](https://profiles.wordpress.org/marale/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_current_user/#comment-2506)
 17. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-2506)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-2506)
 18. You can use it from the [plugins_loaded](https://developer.wordpress.org/reference/hooks/plugins_loaded/)
     hook on.
 19.  * This doesn’t seem to be correct. On [this page](https://codex.wordpress.org/Plugin_API/Action_Reference)
        it is listed as firing before “init” hook, which is a hook when current user
        is being set: “Init: Typically used by plugins to initialize. The current user
        is already authenticated by this time.”
      * [LatePoint](https://profiles.wordpress.org/latepoint/) [4 years ago](https://developer.wordpress.org/reference/functions/wp_get_current_user/#comment-6279)
 20.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%3Freplytocom%3D2506%23feedback-editor-2506)
 21.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#comment-content-7037)
 22.   [Akramul Hasan](https://profiles.wordpress.org/wpfy/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_current_user/#comment-7037)
 23. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-7037)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-7037)
 24. **Checking User Role**
 25. This example demonstrates how to find if the user is an admin.
 26.     ```php
         $user = wp_get_current_user();
     
         if ( in_array( 'administrator', $user->roles ) ) {
         	// If the user is an admin, do something
         } else {
         	// If the user is not an admin, do something
         	echo do_shortcode( '[posts_table id="1" author="' . $user_id . '"]' );
         }
         ```
     
 27.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%3Freplytocom%3D7037%23feedback-editor-7037)
 28.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/wp_get_current_user/?output_format=md#comment-content-438)
 29.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_current_user/#comment-438)
 30. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-438)
     Vote results for this note: -8[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%23comment-438)
 31. **Checking Other User Attributes**
      This example demonstrates how to manually 
     determine if a user is logged in.
 32. _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()`.
 33.     ```php
         function wpdocs_check_logged_in() {
         	$current_user = wp_get_current_user();
         	if ( 0 == $current_user->ID ) {
         	    // Not logged in.
         	} else {
         	    // Logged in.
         	}
         }
         add_action( 'init', 'wpdocs_check_logged_in' );
         ```
     
 34.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F%3Freplytocom%3D438%23feedback-editor-438)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_current_user%2F)
before being able to contribute a note or feedback.