Title: current_user_can() in the __construct?
Last modified: August 19, 2016

---

# current_user_can() in the __construct?

 *  Resolved [JesperT](https://wordpress.org/support/users/jespert/)
 * (@jespert)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/current_user_can-in-the-_construct/)
 * When I use _current\_user\_can()_ in the __construct function in my plugin I’ll
   get this error: **Fatal error: Call to undefined function wp_get_current_user()
   in C:\Inetpub\WP\wp-includes\capabilities.php on line 969**
 *     ```
       class myPlugin {
           public function __construct() {
               if(current_user_can('manage_options'))
               add_action("publish_post",array(&$this,'save_post_form'));
           }
       }
       ```
   
 * Is it not possible to run the _current\_user\_can()_ in the _\_\_construct_-funktion?

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

 *  [s0what](https://wordpress.org/support/users/s0what/)
 * (@s0what)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/current_user_can-in-the-_construct/#post-1397332)
 * same problem for me. Maybe becouse of new WP version?
 *  [Warren Harrison](https://wordpress.org/support/users/hungrymedia/)
 * (@hungrymedia)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/current_user_can-in-the-_construct/#post-1397341)
 * I just ran into the same problem today. Seems this function is not working in
   the latest WP version (2.9.2)
 *  [Txanny](https://wordpress.org/support/users/txanny/)
 * (@txanny)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/current_user_can-in-the-_construct/#post-1397361)
 * You cannot run this on the plugin load. I think you are instantiating the class
   as soon as the plugin loads.
 * wp_get_current_user() is a pluggable function. This means that can be replaced
   by plugins. Because of that, this functions library is only available after plugins
   are loaded.
 * Try calling it on the ‘plugins_loaded’ action hook:
 *     ```
       class myPlugin {
         public function __construct () {
           add_action('plugins_loaded', array($this, 'pluginInit');
         }
   
         public function pluginInit () {
           if(current_user_can('manage_options'))
             add_action("publish_post",array(&$this,'save_post_form'));
         }
       }
       ```
   
 *  [Warren Harrison](https://wordpress.org/support/users/hungrymedia/)
 * (@hungrymedia)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/current_user_can-in-the-_construct/#post-1397380)
 * Aha! Good to know. That solved my issue. Thank you.
 *  Thread Starter [JesperT](https://wordpress.org/support/users/jespert/)
 * (@jespert)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/current_user_can-in-the-_construct/#post-1397395)
 * **Tnx!**

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

The topic ‘current_user_can() in the __construct?’ is closed to new replies.

## Tags

 * [current_user_can](https://wordpress.org/support/topic-tag/current_user_can/)
 * [__construct](https://wordpress.org/support/topic-tag/__construct/)

 * 5 replies
 * 4 participants
 * Last reply from: [JesperT](https://wordpress.org/support/users/jespert/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/current_user_can-in-the-_construct/#post-1397395)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
