Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use deleted_plugin action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
May 20, 2023
5 minutes read

Alright, my fellow WordPress enthusiasts! Let’s dive into the fascinating world of WordPress hooks. Today, we’re going to chat about the deleted_plugin action hook. This nifty hook fires right after you attempt to delete a plugin. It’s like the cleanup crew swooping in after the main event. Now, before we get started, remember that to use the deleted_plugin action, you need to register it first. You can pop this code into the functions.php file of your active theme or, better yet, create a custom WordPress plugin. At WePlugins, we always recommend the latter so that nothing breaks when you update your theme.

Example 1: Basic Usage of deleted_plugin

Here’s a basic example of how you can use the deleted_plugin hook. This function will trigger whenever a plugin is deleted.

    function weplugins_execute_on_deleted_plugin_event($plugin_file, $deleted){
        // Custom code to execute after a plugin is deleted.
    }
    add_action("deleted_plugin", "weplugins_execute_on_deleted_plugin_event", 10, 2);
    

Example 2: Removing a Hook Callback

Sometime you might need to remove a registered hook. Here’s how you can remove the deleted_plugin action.

    remove_action("deleted_plugin", "weplugins_execute_on_deleted_plugin_event", 10, 2);
    

Example 3: Advanced Custom Functionality

Let’s take it up a notch and add some advanced functionality. Use the parameters received in the function to implement additional custom features.

    function weplugins_advanced_deleted_plugin_function($plugin_file, $deleted){
        if($deleted) {
            // Log the deletion or perform other custom actions
        }
    }
    add_action("deleted_plugin", "weplugins_advanced_deleted_plugin_function", 10, 2);
    

That’s all there is to it! The deleted_plugin action hook can be quite powerful when used wisely.

Access Premium WordPress Plugins

Contact Us

If you need any customization or run into issues, don’t hesitate to reach out to us. We’re here to help! Visit our Contact Page to get in touch.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.