WordPress.org

Ready to get started?Download WordPress

Forums

Get current user id in plugin (7 posts)

  1. levani01
    Member
    Posted 4 years ago #

    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

  2. s0what
    Member
    Posted 4 years ago #

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

  3. Mark / t31os
    Moderator
    Posted 4 years ago #

    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..

  4. renato7x
    Member
    Posted 4 years ago #

    it's not working in wordpress 2.9...
    is there another solution?

  5. Mark / t31os
    Moderator
    Posted 4 years ago #

    global $current_user;
    get_currentusrinfo();
    echo $current_user->ID;
  6. MichaelH
    Member
    Posted 4 years ago #

    small fix:

    global $current_user;
    get_currentuserinfo();
    echo $current_user->ID;
  7. Mark / t31os
    Moderator
    Posted 4 years ago #

    Thank you. :)

Topic Closed

This topic has been closed to new replies.

About this Topic