WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use information about the current user in a plugin that I am designing and I have seen people go about it in several different ways.

My Way

This way seems to work, but am I missing something?

global $current_user;

// Use information
echo "User ID: " . $current_user->user_id;
echo "User First Name: " . $current_user->first_name;

I have seen some people call the function get_currentuserinfo() on the next line after declaring the global variable $current_user. However, this seems to work without that call - so is it necessary?

Also, there is the function wp_get_current_user() - what is the difference between this and get_currentuserinfo()?

I have also seen people use a global variable called $profileuser and use get_user_to_edit() in order to set it to the user object. Is there some benefit to this?

I have also seen people refer directly to the $user_ID global variable in addition to using the $current_user. Why wouldn't they just use $current_user->ID?

Thanks, William

share|improve this question
up vote 6 down vote accepted

1, call the function get_currentuserinfo() on the next line after declaring the global variable $current_user

2, what is the difference between wp_get_current_user() and get_currentuserinfo()?

function wp_get_current_user() {
    global $current_user;


    return $current_user;

I think the source code answers your first two questions, right?

Remember that wp_get_current_user is defined in wp-includes/pluggable.php so it can be overridden.

Also, it is safe to stick with global $current_user this is because Wordpress calls wp_get_current_user during initialization.

Specifically, wp-settings.php -> new WP -> WP->init() -> wp_get_current_user

The usage of $profileuser, this global variable is only available when you are editing a user (user-edit.php) and the data will be thereof.

The last one questions I don't really know how to answer so I'll leave to others.

Hope you don't mind.

BTW: leaving your name in the ending seems to violate the rule.

share|improve this answer
I know doing homework and reading manuals sucks, but the pages faq, tour, How to Ask and How to Answer are really helpful to get the best of the Stack. Rant aside, very good Question and Answer, kudos for that, +1 to both! – brasofilo Mar 9 '13 at 14:36
Awesome answer! – William Mar 9 '13 at 18:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.