WordPress Plugin uninstall hook – register_uninstall_hook()

Today, We want to share with you WordPress Plugin uninstall hook – register_uninstall_hook().In this post we will show you Uninstall – WordPress Plugin Development, hear for WORDPRESS PLUGIN ACTIVATION, DEACTIVATION, AND UNINSTALLATION we will give you demo and example for implement.In this post, we will learn about Keeping Plugins Clean: Using Activate, Deactivate and Uninstall Hooks with an example.

WordPress Plugin uninstall hook – register_uninstall_hook()

There are the Following The simple About WordPress Plugin uninstall hook – register_uninstall_hook() Full Information With Example and source code.

As I will cover this Post with live Working example to develop wordpress plugin uninstall delete table, so the how to activate custom plugin in wordpress for this example is following below.

Simple example of functions for WordPress plugin activation/deactivation/uninstallation.

function plugin_activation()
{
    flush_rewrite_rules();
}

function plugin_deactivation()
{
    flush_rewrite_rules();
}

function plugin_uninstall()
{
	delete_option( 'some name' );
    //Some stuff
}

register_activation_hook(__FILE__, 'plugin_activation');
register_deactivation_hook(__FILE__, 'plugin_deactivation');
register_uninstall_hook(__FILE__, 'plugin_uninstall');

using register_uninstall_hook()

function custom_ng4free_db_clients_uninstall()
{
    global $wpdb;
    $table_name = $wpdb->prefix . 'products';
    $my_query_sql = "DROP TABLE IF EXISTS $table_name";
    $wpdb->query($my_query_sql);
    delete_option('ng4free_time_card_version');
}

register_uninstall_hook(__FILE__, 'custom_ng4free_db_clients_uninstall');

PHP register_uninstall_hook Examples

uninstall.php

if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    exit;
}

// Uninstallation code here

Activation Hook

register_activation_hook( $file, $function );

Deactivation Hook

register_deactivation_hook($file, $function);

Uninstall Hook

register_uninstall_hook( $file, $function )
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about WordPress Plugin uninstall hook.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment