Title: Wrong using get_current_user_id function
Last modified: July 18, 2019

---

# Wrong using get_current_user_id function

 *  Resolved [ioannup](https://wordpress.org/support/users/ioannup/)
 * (@ioannup)
 * [7 years ago](https://wordpress.org/support/topic/wrong-using-get_current_user_id-function/)
 * In your plugin, you try to get get_current_user_id() earlier than it’s possible.
   [https://i.imgur.com/4xnQC26.png](https://i.imgur.com/4xnQC26.png) It’s always
   0 in this place. You can check `wp-settings.php` file where your code is running
   and then, it includes `pluggable.php` file where defining get_current_user_id
   function [https://i.imgur.com/Q3zEw0S.png](https://i.imgur.com/Q3zEw0S.png)
    
   That’s why your plugin has a lot of issues with other plugins in Admin area if`
   Custom contact forms` setting is enabled. So, you can use `get_current_user_id`
   function only at least after `plugins_loaded` action.
    -  This topic was modified 7 years ago by [ioannup](https://wordpress.org/support/users/ioannup/).

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

 *  Plugin Author [alexandergull](https://wordpress.org/support/users/alexandergull/)
 * (@alexandergull)
 * [7 years ago](https://wordpress.org/support/topic/wrong-using-get_current_user_id-function/#post-11551251)
 * Hello, [@ioannup](https://wordpress.org/support/users/ioannup/).
 * Thank you for your feedback.
 * We will discuss your suggestion with the team.
 * And we will let you know about results.
 * Be well,
 *  [Safronik](https://wordpress.org/support/users/safronik/)
 * (@safronik)
 * [7 years ago](https://wordpress.org/support/topic/wrong-using-get_current_user_id-function/#post-11564807)
 * Hello,
 * Fixed! Thank you so much for pointing on this flaw!
    Unfortunately we can’t use
   plugins_loaded hook for our purposes. So we made ours apbct_wp_get_current_user().
 * You can see all changes here: [https://downloads.wordpress.org/plugin/cleantalk-spam-protect.zip](https://downloads.wordpress.org/plugin/cleantalk-spam-protect.zip)
 * Contact us if you have questions or suggestions.
 *  [Biplav](https://wordpress.org/support/users/bplv/)
 * (@bplv)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/wrong-using-get_current_user_id-function/#post-11742604)
 * [@safronik](https://wordpress.org/support/users/safronik/) [@alexandergull](https://wordpress.org/support/users/alexandergull/)
   
   You are directly changing the global variable in the new method i.e. `apbct_wp_get_current_user()`
   which causes some hooks like `set_current_user` to not run at all. This can cause
   problems for other plugins who rely on that hook. Also, if I’m not mistaken modifying
   global variables is against the WordPress development guidelines as well. If 
   possible please use this method instead `wp_set_current_user()`.
 *  Plugin Support [sergecleantalk](https://wordpress.org/support/users/sergecleantalk/)
 * (@sergecleantalk)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/wrong-using-get_current_user_id-function/#post-11742849)
 * Hello,
 * I’ve transferred your request to our developers. They will answer you within 
   1-2 working days.
 *  Plugin Support [sergecleantalk](https://wordpress.org/support/users/sergecleantalk/)
 * (@sergecleantalk)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/wrong-using-get_current_user_id-function/#post-11745341)
 * Thank you for your reply. We will fix this.

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

The topic ‘Wrong using get_current_user_id function’ is closed to new replies.

 * ![](https://ps.w.org/cleantalk-spam-protect/assets/icon-256x256.gif?rev=3539767)
 * [Anti-Spam by CleanTalk. Spam protection](https://wordpress.org/plugins/cleantalk-spam-protect/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cleantalk-spam-protect/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cleantalk-spam-protect/)
 * [Active Topics](https://wordpress.org/support/plugin/cleantalk-spam-protect/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cleantalk-spam-protect/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/)

 * 5 replies
 * 5 participants
 * Last reply from: [sergecleantalk](https://wordpress.org/support/users/sergecleantalk/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/wrong-using-get_current_user_id-function/#post-11745341)
 * Status: resolved