The MU forums have moved to WordPress.org

User_id does not seem to be set (11 posts)

  1. BjornW
    Member
    Posted 17 years ago #

    I need to get the currently logged in user data fro my plugin and I expected it to be available via global $userdata. However that did not seem to work. Which global variable can I use for this purpose?

  2. lunabyte
    Member
    Posted 17 years ago #

    global $current_user

    Print it out as a test, and you can see what data it stores.

  3. BjornW
    Member
    Posted 17 years ago #

    Thanks, but this does not seem to work. I'm trying this:

    global $current_user;
    var_dump($current_user);

    This results in the value NULL being printed.

    BTW I do this in my plugin in the plugin directory (not the mu-plugins directory).

  4. lunabyte
    Member
    Posted 17 years ago #

    I said print it out. It's an object array.

  5. BjornW
    Member
    Posted 17 years ago #

    Thanks again, but var_dump will display any contents of the variable if any. It's a print or echo on steroids very useful for debugging purposes especially when there are object and/or arrays involved.

    See also http://nl2.php.net/manual/en/function.var-dump.php

    Or am I totally missing your point?

  6. lunabyte
    Member
    Posted 17 years ago #

    Missing my point, I guess.

    print_r works just fine. Same thing pretty much though. Although I've had instances where vd didn't work, but print_r did.

    Looking at one of my functions I've added, I did try a vd on it, and it worked OK.

  7. BjornW
    Member
    Posted 17 years ago #

    Lunabyte, where are you using print_r? In your plugin? In which directory?

  8. lunabyte
    Member
    Posted 17 years ago #

    If I need to see the contents of an array, I'll use it.

    For example, let's say I have a standard user information area when someone is logged into my "MU network".

    Maybe I'd like to add some more info, but is it already available to the script without an addiditonal db call?

    So maybe I have a list with a welcome message, logout link, etc.
    At the bottom of that, for testing, I'll just

    <?php print_r($var); ?>

    Then I can read what keys are available, and see if there is anything I want to use.

    Once I find it, I call the keys I want, and take out the print.

  9. BjornW
    Member
    Posted 17 years ago #

    Ok, I just found my problem. I was calling the $current_user even before it was created. Thanks for helping out.

  10. suleiman
    Member
    Posted 17 years ago #

    so when exactly is the current user created?

  11. marclzipca
    Member
    Posted 16 years ago #

    I have the same problem... how do you make sure that it is created before you run code in your plugin?

About this Topic

  • Started 17 years ago by BjornW
  • Latest reply from marclzipca