Get logged in user info – call to undefined function (2)

I’m reposting this question because the problem wasn’t solved.
In a relevant question the answer below may be the solution.

Apparently this is happening because the file /wp-includes/pluggable which contains the function doesn’t get loaded until after the plugins are loaded.
Indeed it is. So wrap whichever thing you’re doing in a function, and hook it onto the plugins_loaded or init hook. (see the wp-settings.php file)

Read More

Where exactly do I write the add_action(‘plugins_loaded’,’my_function’); command?
In the “wp-settings file”, the “pluggable” or my own php file?
All I want to do is to display the user info in a php file which is loaded in a page in wordpress,but I’m constantly getting the same error “call to undefined function”.
I’ve tried including the relevant php file, still doesn’t work.

 <?php 
 global $current_user;
 get_currentuserinfo();
 echo $current_user->user_login;
 ?>

Related posts

Leave a Reply

1 comment

  1. This might work for you!!

    require (ABSPATH . WPINC . '/pluggable.php');
    global $current_user;
    get_currentuserinfo();
    echo $current_user->user_login;
    

    All you do is include the pluggable.php file in your plugin.