The Wordpress current user information is available through this global variable. It is an instance of class WP_User defined in [wp root folder]/wp-includes/capabilities.php. It is set in the pluggable function set_current_user($id, $name='') and get_currentuserinfo() in [wp root folder]/wp-includes/pluggable-functions.php.
The class WP_User has methods for role and capabilities of the user.
WP_User($id, $name = ''): the constructor, it can be used to instantiate a user with specific user ID.get_role_caps(): gets capabilitiesadd_role($role): adds specified role to the userremove_role($role): removes specified roleset_role($role): sets rolelevel_reduction($max, $item): reduces levelupdate_user_level_from_caps(): translates from capabilities to user levelsadd_cap($cap, $grant = true): adds capabilitiesremove_cap($cap): removes capabilitieshas_cap($cap): queries for a specific capabilitytranslate_level_to_cap($level): translates from level to capabilities
User ID of the current user can be accessed using $current_user->id field. Profile information of the current user can be obtained by using by using the member variable $current_user->data, but other global variables are available like $user_login, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5 and $user_identity for this information.
Plugin and theme authors can use this global variable to get information about the current user. Most commonly required information would be about what the current user can do. Wordpress provides the function current_user_can($capability) for finding out capabilities of the user. The different capabilities are the different actions a user can take, they are:
- switch_themes
- edit_themes
- activate_plugins
- edit_plugins
- edit_users
- edit_files
- manage_options
- moderate_comments
- manage_categories
- manage_links
- upload_files
- import
- unfiltered_html
- edit_posts
- edit_others_posts
- edit_published
- publish_posts
- edit_pages
- read
- level_10
- level_9
- level_8
- level_7
- level_6
- level_5
- level_4
- level_3
- level_2
- level_1
- level_0
Update
As mentioned by Mark Jaquith in the comments, level_* are deprecated and are available only for backward compatibility. New plugins and themes should not use them. The methods concerned with levels should also be avoided.
There are some more functions available like user_can_edit_post and similar, but they are deprecated. current_user_can should be used instead of these.
Back to full list of global variables.
Technorati tags: current_user, current_user_can, wp_user



March 6th, 2006 at 7:44 pm
[...] $current_user [...]
March 7th, 2006 at 12:45 pm
Thanks a lottttttttttt
I am new to WP and benefited from your post, regarding the display of author’s name.
Thanks,
March 28th, 2006 at 11:23 am
Very nice. Just to be clear, the
level_ones are for backwards compatability only and should not be used for new code.November 7th, 2008 at 6:12 am
Hello, is it possible to access these variables outside the wordpress directory? I have setup wordpress under /blog. And under my root folder I have setup a separate registration and login page, where the users can successfully register and login(I know they can login because you can login, goto the blog page and see that your logged in.)
However when they login, the $current_user->ID returns 0 outside of a wordpress file. I try to display the other global values you’ve listed and they are all empty. Is there a step im missing to initiate the session or something?