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?
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?
global $current_user
Print it out as a test, and you can see what data it stores.
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).
I said print it out. It's an object array.
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?
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.
Lunabyte, where are you using print_r? In your plugin? In which directory?
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.
Ok, I just found my problem. I was calling the $current_user even before it was created. Thanks for helping out.
so when exactly is the current user created?
I have the same problem... how do you make sure that it is created before you run code in your plugin?