I just had a look at Global variables in WP and I discovered that a lot has changed since the last time I looked.
$current_user
is no longer listed. Does that mean this and many other (old) globals will be “phased out” from future WP versions?
I just had a look at Global variables in WP and I discovered that a lot has changed since the last time I looked.
$current_user
is no longer listed. Does that mean this and many other (old) globals will be “phased out” from future WP versions?
Comments are closed.
The
$current_user
is still a valid global, however like all globals, you should avoid relying on them.If you need the current user in a function, do this instead:
$current_user = wp_get_current_user();
Also be aware that this may return false if no user is logged in on the current request, while the global $current_user may simply be an invalid instance of the WP_User (with an ID of zero). This is for backwards compatibility, and a wonderful reason to not rely on the globals.
When it snows in hell.
WordPress has extreme backwards compatibility commitment. It is very unlikely anything like global variable will be just removed, without much advance notice and being in deprecated status for literally years.
However that is no excuse for sloppy code practices and really anything that can be accessed via proper API functions (rather than globals), should be whenever at all possible.
PS I would not rely on Codex as indicator of state of code base too much. When wondering about code – look at code.