Title: Fatal error when programmatically deactivating a plugin
Last modified: October 26, 2021

---

# Fatal error when programmatically deactivating a plugin

 *  Resolved [Gregor Capuder](https://wordpress.org/support/users/capuderg/)
 * (@capuderg)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/fatal-error-when-programmatically-deactivating-a-plugin-2/)
 * Hi,
 * our user got the fatal error below when they tried to activate our WP Mail SMTP
   Pro version over the Lite version. We prevent that in our plugin and deactivate
   the Pro version automatically (in code).
 *     ```
        PHP Fatal error:  Uncaught Error: Call to undefined function wp_get_current_user() in .../wp-content/plugins/sg-security/core/Activity_Log/Activity_Log_Helper.php:20
       ```
   
 * If you inspect that code you will see that you are using `wp_get_current_user`
   function. But because this deactivation happens very early on in the process 
   of WP this function is not yet defined by WP core. You’ll need to require the
   pluggable.php WP core file in your `Activity_Log_Helper::log_event` function,
   to prevent this error from happening:
 * `require_once ABSPATH . WPINC . '/pluggable.php';`
 * I hope you can include this fix in your upcoming plugin update.
 * Thank you and take care!

Viewing 1 replies (of 1 total)

 *  Plugin Author [Stoyan Georgiev](https://wordpress.org/support/users/stoyangeorgiev/)
 * (@stoyangeorgiev)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/fatal-error-when-programmatically-deactivating-a-plugin-2/#post-15014023)
 * Hey there [@capuderg](https://wordpress.org/support/users/capuderg/) ,
 * Thank you for the recommendation. We will try to provide a fix for that issue
   upon the next release of the plugin.
 * Kind regards,
    Stoyan

Viewing 1 replies (of 1 total)

The topic ‘Fatal error when programmatically deactivating a plugin’ is closed to
new replies.

 * ![](https://ps.w.org/sg-security/assets/icon-256x256.gif?rev=2971855)
 * [Security Optimizer - The All-In-One Protection Plugin](https://wordpress.org/plugins/sg-security/)
 * [Support Threads](https://wordpress.org/support/plugin/sg-security/)
 * [Active Topics](https://wordpress.org/support/plugin/sg-security/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sg-security/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sg-security/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Stoyan Georgiev](https://wordpress.org/support/users/stoyangeorgiev/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/fatal-error-when-programmatically-deactivating-a-plugin-2/#post-15014023)
 * Status: resolved