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.

Read Also:  Remove undefined value from jquery array

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 :

Read Also:  jQuery Validate CKEditor value is blank or not

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Angular 6 applications - Insert, Fetch , Edit - update , Delete Operations
  2. Read Also:  Angularjs Get first and last value of list-item (li)
  3. Read Also:  Remove null values from array in PHP
  4. Read Also:  UI Grid (ng-grid) using Angular Example
  5. Read Also:  How to Open URL in New Tab using ASP.NET
  6. Read Also:  [SOLUTIONS] 504 GATEWAY TIMEOUT NGINX
  7. Read Also:  Laravel delete foreign key Constraint Using Migration
  8. Read Also:  Laravel 6 Insert Update and Delete record from MySQL
  9. Read Also:  CodeIgniter Login Registration Example Tutorial From Scratch
  10. Read Also:  how to create dynamic calendar in html?