WordPress.org

Forums

The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Get current user id in plugin (7 posts)

  1. levani01
    Member
    Posted 6 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 6 years ago #

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

  3. Mark / t31os

    Posted 6 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 6 years ago #

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

  5. Mark / t31os

    Posted 6 years ago #

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

    small fix:

    global $current_user;
    get_currentuserinfo();
    echo $current_user->ID;
  7. Mark / t31os

    Posted 6 years ago #

    Thank you. :)

Topic Closed

This topic has been closed to new replies.

About this Topic