Title: Get current user id in plugin
Last modified: August 19, 2016

---

# Get current user id in plugin

 *  [levani01](https://wordpress.org/support/users/levani01/)
 * (@levani01)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/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](https://wordpress.org/support/users/s0what/)
 * (@s0what)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/get-current-user-id-in-plugin/#post-1342640)
 * same problem for me. I want to get current page ID or name inside plugin
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/get-current-user-id-in-plugin/#post-1342641)
 *     ```
       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](https://wordpress.org/support/users/renato7x/)
 * (@renato7x)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/get-current-user-id-in-plugin/#post-1342645)
 * it’s not working in wordpress 2.9…
    is there another solution?
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/get-current-user-id-in-plugin/#post-1342646)
 *     ```
       global $current_user;
       get_currentusrinfo();
       echo $current_user->ID;
       ```
   
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/get-current-user-id-in-plugin/#post-1342647)
 * small fix:
 *     ```
       global $current_user;
       get_currentuserinfo();
       echo $current_user->ID;
       ```
   
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/get-current-user-id-in-plugin/#post-1342649)
 * Thank you. 🙂

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

The topic ‘Get current user id in plugin’ is closed to new replies.

## Tags

 * [current user](https://wordpress.org/support/topic-tag/current-user/)
 * [id](https://wordpress.org/support/topic-tag/id/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 5 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/get-current-user-id-in-plugin/#post-1342649)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
