How to log and notify via email when a WordPress plugin is disabled or deleted?

Sometimes, you want to make sure that a specific esssential plugin is never deleted on your WordPress website or at least you want to be notified when ever this happens.

Imagine you have a tax plugin that calculates the tax in your WooCommerce or Easy Digital Downloads shop system. If this plugin is disabled for a reason, all your purchase prices will be miscalculated and it can take a while until you recognize that.

There is no 100% protection to prevent a plugin from being disabled on your WordPress website, but when it happens, you can copy the following code into a mu-plugin like plugin-logger.php and add it to the folder wp-content/mu-plugins

Once any of the installed plugins is either disabled or deleted by the WordPress hooks deleted_plugin or deactivated_plugin you will get an email notification. It will also log the report in the file wp-content//7263767234-deleted-plugins.log.

I recommend to adjust the path and file name for security purposes.

Rene Hermenau

Author: Rene Hermenau

About the author: René Hermenau is the founder of WP STAGING. He works on WordPress backups, staging, migrations, database handling, and safe deployment workflows.