r

How to Uninstall and delete data after Wordpress Plugin Deactivation

How to Uninstall and delete data after Wordpress Plugin Deactivation:-

Please like and Subscribe my youTube channel for learn programming(php,nodejs,angularjs Tutorials) in easy way:-




We've launched a New Technical Blog for Web Blogging and Complete tips and Tricks, Module Download Source codes



Please visit:- Technology Shouters 

https://www.technologyshouters.com/


https://www.technologyshouters.com/

Google Recruitment 2017 for freshers – Apply for Google Jobs

IBM Recruitment 2017 for Freshers – Apply for IBM Jobs 2017


Google Interview Questions and Answers -Hiring Process & Sample Papers

Build a Tagging system with HTML Bootstrap Tagsinput library

Login with Facebook in Laravel 5.5 Socialite – Complete Source Code

TCS Technical Interview Questions and Answers – PDF DOWNLOAD

Search functionality in Laravel 5.5 With Pagination – Source Code

TCS Placement Papers and Online Test Pattern 2017-18 – Free PDF Download

How to : Create Beautiful Analog & Digital Clock in HTML5 and CSS3

https://www.technologyshouters.com/


1.Simply Create Uninstall.php and link it to your plugin

<?php
// If uninstall is not called from WordPress, exit
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit();
}

$keep = get_option( 'shw-setting' );
if ( $keep != 'yes' ) {
// Delete custom post meta
delete_post_meta_by_key( 'show-date' );
delete_post_meta_by_key( 'show-time' );
delete_post_meta_by_key( 'show-time2' );
delete_post_meta_by_key( 'show-location' );
delete_post_meta_by_key( 'show-link' );
delete_post_meta_by_key( 'show-link-label' );
delete_post_meta_by_key( 'show-link-target' );

// Deprecated custom post meta
delete_post_meta_by_key( 'show-date-hide' );

// Delete option
delete_option( 'widget_shw_widget' );
delete_option( 'shw-setting' );
delete_option( 'shw-setting-1' );
delete_option( 'shw-setting-2' );
delete_option( 'shw-setting-3' );
delete_option( 'shw-setting-4' );
delete_option( 'shw-setting-5' );
delete_option( 'shw-setting-6' );
delete_option( 'shw-setting-7' );
delete_option( 'shw-setting-8' );
delete_option( 'shw-setting-9' );

// Set global
global $wpdb;

// Delete terms
$wpdb->query( "
DELETE FROM
{$wpdb->terms}
WHERE term_id IN
( SELECT * FROM (
SELECT {$wpdb->terms}.term_id
FROM {$wpdb->terms}
JOIN {$wpdb->term_taxonomy}
ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id
WHERE taxonomy = 'show_cat'
) as T
);
  " );

// Delete taxonomies
$wpdb->query( "DELETE FROM {$wpdb->term_taxonomy} WHERE taxonomy = 'show_cat'" );

// Delete shows
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type = 'show'" );
}

?>

Oldest