I am writing my own plugin and I am stuck quite early on. I am trying to get the ID of currently logged in user, via php script. Something like this
add_action('init','do_stuff');
function do_stuff(){
$current_user = wp_get_current_user();
// rest of my code here
}
However I am always getting the result 0.
I am aware that there are multiple similar questions, but literally no solutions worked so far. E.g.
wp_get_current_user always returns 0
wp_get_current_user() function not working in Rest API callback function