• owencutajar

    (@owencutajar)


    I’ve written a plugin (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)

    (@otto42)

    WordPress.org Admin

    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

    (@owencutajar)

    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 …

    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.

    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.