Title: get_currentuserinfo() is empty?
Last modified: August 18, 2016

---

# get_currentuserinfo() is empty?

 *  [owencutajar](https://wordpress.org/support/users/owencutajar/)
 * (@owencutajar)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/get_currentuserinfo-is-empty/)
 * I’ve written a plugin ([http://www.u-g-h.com/index.php/wordpress-plugins/wordpress-plugin-comment-email-responder/](http://www.u-g-h.com/index.php/wordpress-plugins/wordpress-plugin-comment-email-responder/))
   which uses a number of hooks into a page, specifically get_comment_author_link,
   comment_form and comment_post. The triggered code includes a fairly typical
    `
   global $userdata; get_currentuserinfo();` sequence.
 * The plugin works fine in most cases, however a number of people complain that
   the plugin doesn’t work for them. I’ve manage to replicate a scenario where get_currentuserinfo()
   doesn’t return anything in these cases. Does anyone have any idea why?
 * I’m aware that the init() hook sometimes resolves this issue, but if these are
   hooks fired at page generation then I don’t see why the user info isn’t populated..
 * Help 🙁

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 1 month ago](https://wordpress.org/support/topic/get_currentuserinfo-is-empty/#post-554796)
 * The only thing I can think of is if you’re calling get_currentuserinfo() at the
   time the plugin loads, which won’t work because it’s not defined yet. All that
   functionality is in the pluggable functions, which load after the plugins load.
   So you have to defer that call until at least the plugins_loaded action hook (
   which fires just after pluggable.php gets loaded).
 * Now, if you’re doing this at the time of page generation (off a hook or function
   call somewhere in the theme), then it should work just fine, since that’s well
   after that point.
 * The other possibility is that something is messing with the incoming cookies.
   The login is based on the cookie information being sent by the browser. Anything
   messing with those = no login info.
 *  Thread Starter [owencutajar](https://wordpress.org/support/users/owencutajar/)
 * (@owencutajar)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/get_currentuserinfo-is-empty/#post-554799)
 * Thanks Otto,
 * The code is definitely being called off page generation as sticking a couple 
   of test echo statements outputs the code right where I would expect it (right
   next to comment authors)
 * re cookies, I don’t think they’re messed up, as the blog still recognises me 
   as being logged in (unlike my personal one on IIS with a custom 404 permalink
   thingy which forgets who I am when I go to a permalinked page)
 * So, still no solution, but at least your answer confirms I’m not going nuts …
 *  [eclectichermit](https://wordpress.org/support/users/eclectichermit/)
 * (@eclectichermit)
 * [19 years ago](https://wordpress.org/support/topic/get_currentuserinfo-is-empty/#post-555175)
 * owencutajar:
 * I’ve encountered the same problem, and it’s not just $userdata that goes empty.
   I’ve noticed my own global variables go empty as well.
 * For example sometimes a var_dump($userdata) before header.php is included gives
   normal results, but it’s empty after inclusion.
 * I don’t know what causes the problem, but I’ve worked around it by ‘resetting’
   userdata to the superglobal $GLOBALS[‘userdata’] as follows:
 * >     ```
   >     $userdata = $GLOBALS['userdata'];
   >     ```
   > 
 * or
 * >  `$myGlobalVariable = $GLOBALS['myGlobalVariable']`
 * Hope this helps.
 *  [andrewpeacock](https://wordpress.org/support/users/andrewpeacock/)
 * (@andrewpeacock)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/get_currentuserinfo-is-empty/#post-555220)
 * Note: you have to do
    `global $userdata;` at the beginning of the function in
   which you’re calling get_currentuserinfo();
 * Andy

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘get_currentuserinfo() is empty?’ is closed to new replies.

## Tags

 * [empty](https://wordpress.org/support/topic-tag/empty/)
 * [get_currentuserinfo](https://wordpress.org/support/topic-tag/get_currentuserinfo/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 4 participants
 * Last reply from: [andrewpeacock](https://wordpress.org/support/users/andrewpeacock/)
 * Last activity: [18 years, 5 months ago](https://wordpress.org/support/topic/get_currentuserinfo-is-empty/#post-555220)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
