0

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
1

1 Answer 1

3

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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.