$current_user global – Is it automatically loaded?
I am working on writing a plugin, in which I need to get the current logged in user’s ID. I know that I can do this like so with the
global $current_user; $userID = $current_user->ID;
There are several places in the plugin where I need this. My question is, can I count on this global always being loaded, i.e., is it loaded automatically by WordPress on each run? Or do I need to check if it’s set and then call get_currentuserinfo() if it isn’t?
global $current_user; get_currentuserinfo(); echo $current_user->ID;
I don’t want to be calling the get_currentuserinfo() function unnecessarily (though I guess it really wouldn’t make that much difference), and I couldn’t find anything definite in the documentation.
- The topic ‘$current_user global – Is it automatically loaded?’ is closed to new replies.