Wordpress php can't get current user ID in a plugin
<p>I have been struggling to get the current user ID in a wordpress plugin I am building. I have tried what seems to be everything, with still no luck.</p>

<p>The closest I have got is being able to return a '0' and then the user ID (so in the case of admin, I can return "ID: 0 ID: 1".</p>

<p>Here is the code that does that for me:</p>

<pre><code>add_action('admin_init', 'myFunction');

function myFunction(){
    $user_ID= get_current_user_id();   
    echo "ID: ".$user_ID;
}
</code></pre>

<p>Obviously I have wrapped it in a function here that fires on admin init.</p>

<p>What's particularly strange is that in other files in my plugin, I am able to get user info using </p>

<pre><code>global $current_user;
get_currentuserinfo();
$current_user-&gt;ID
</code></pre>

<p>But this trigger a fatal error </p>

<pre><code>Fatal error: Call to undefined function get_currentuserinfo() 
</code></pre>

<p>...even if I wrap it in my function.</p>

<p>Surely this is a simple thing to achieve? Can anyone tell me how I do this</p>