I am currently developing a plugin and I am trying to make use of the $current_user global.
class Something {
public function __construct() {
$this->get_user();
var_dump( $this->user );
}
private function get_user() {
require_once( ABSPATH . '/wp-includes/pluggable.php' );
$this->user = wp_get_current_user();
}
}
This actually works. However, I need to call pluggable.php file which shouldn’t be necessary. I have also tried calling the global $current_user variable to no avail: it always returns NULL… unless of course I import pluggable.php again – like so:
private function get_user() {
require_once( ABSPATH . '/wp-includes/pluggable.php' );
global $current_user;
get_currentuserinfo();
$this->user = $current_user;
}
This might be a potential duplicate of: $current_user var returns NULL
And I’ve tried all the solutions, but still need to import pluggable.php no matter what.
Seems like the author of the other thread found a solution that did not share.
Anybody else ever have this issue? Thanks.