-
Call the function
get_currentuserinfo()
on the next line after declaring the global variable$current_user
-
What is the difference between
wp_get_current_user()
andget_currentuserinfo()
?
Below is a snippet:
function wp_get_current_user() {
global $current_user;
get_currentuserinfo();
return $current_user;
}
I think the source code answers your first two questions, right?
Remember that wp_get_current_user()
is defined in wp-includes/pluggable.php
so it can be overridden.
Also, it is safe to stick with global $current_user
this is because WordPress calls wp_get_current_user()
during initialization.
Specifically, wp-settings.php -> new WP -> WP->init() -> wp_get_current_user
The usage of $profileuser
, this global variable is only available when you are editing a user (user-edit.php) and the data will be thereof.
The last one questions I don’t really know how to answer so I’ll leave to others.
Hope you don’t mind.