When I use below in php code, I have a fatal error. What's happen? Let me know any reason.
$current_user = wp_get_current_user();
Fatal error: Call to undefined function is_user_logged_in() in
When I use below in php code, I have a fatal error. What's happen? Let me know any reason.
$current_user = wp_get_current_user();
Fatal error: Call to undefined function is_user_logged_in() in
You call this function too early, before pluggable function is_user_logged_in()
is defined. Try this:
function wpse_get_current_user() {
$current_user = wp_get_current_user();
// do other stuff here
}
add_action( 'init', 'wpse_get_current_user', 10 );