Support » Fixing WordPress » Get current user id in plugin

  • How can I get current user id in plugin? I tried to use $current_user->ID but it doesn’t work (works fine in template files). Any other way?

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • s0what

    (@s0what)

    same problem for me. I want to get current page ID or name inside plugin

    global $current_user;
    echo $current_user->ID;

    If a variable is outside the scope of where you’re trying to call it, then you need to globalise that variable..

    renato7x

    (@renato7x)

    it’s not working in wordpress 2.9…
    is there another solution?

    global $current_user;
    get_currentusrinfo();
    echo $current_user->ID;
    MichaelH

    (@michaelh)

    small fix:

    global $current_user;
    get_currentuserinfo();
    echo $current_user->ID;

    Thank you. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Get current user id in plugin’ is closed to new replies.