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, 5 months ago](https://wordpress.org/support/topic/fatal-error-when-programmatically-deactivating-a-plugin/)
 * 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 get_user_by() in .../wp-content/plugins/aryo-activity-log/classes/class-aal-api.php:89
       ```
   
 * If you inspect that code you will see that you are using `get_user_by` 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 `insert` 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 [Yakir Sitbon](https://wordpress.org/support/users/kingyes/)
 * (@kingyes)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/fatal-error-when-programmatically-deactivating-a-plugin/#post-15008419)
 * Hi [@capuderg](https://wordpress.org/support/users/capuderg/),
 * The plugin listens to the WP actions. When it is fired, assume all WP dependencies
   are loaded.
 * You can deactivate the plugin by selecting one of two options (possibly more):
   –
   Remove the activated plugins from the database (Not recommended). – Remove the
   plugin by sending a request. If you would like to deactivate the plugin, please
   include the other functions before doing so. Its AAL Plugin currently sends an
   error, but another plugin will do it tomorrow.
 * Let me know if that needs to be improved.
 * Thanks

Viewing 1 replies (of 1 total)

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

 * ![](https://ps.w.org/aryo-activity-log/assets/icon-256x256.png?rev=1944199)
 * [Activity Log - Monitor & Record User Changes](https://wordpress.org/plugins/aryo-activity-log/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/aryo-activity-log/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/aryo-activity-log/)
 * [Active Topics](https://wordpress.org/support/plugin/aryo-activity-log/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/aryo-activity-log/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/aryo-activity-log/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Yakir Sitbon](https://wordpress.org/support/users/kingyes/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/fatal-error-when-programmatically-deactivating-a-plugin/#post-15008419)
 * Status: resolved