I'm totally new to WordPress and php. I have a custom table in my Wordpress plugin and I want to delete the custom table when deactivating the plugin (NO when uninstalling it). This is easy to accomplish but before deleting the table I want to ask for confirmation.
function va_deactivation() {
.... //unregisters settings
//Asks for confirmation - Code here
//If answer is yes proceed to delete. If no, doesn't execute the following code
global $wpdb;
$pa_table = $wpdb->prefix."tableName";
$sql = 'DROP TABLE IF EXISTS '.$pa_table;
$wpdb->query( $sql );
}
Any help? Thanks
jQuery(function () {
jQuery('.deactivate a').click(function (e) {
let url = jQuery(this).attr('href');
let regex = /[?&]([^=#]+)=([^&#]*)/g,
params = {},
match;
while (match = regex.exec(url)) {
params[match[1]] = match[2];
}
if(params.plugin === "{plugin_name}%2F{plugin_name}.php"){
let delete_confirm = confirm("You are going deactivate this plugin");
if (delete_confirm !== true) {
e.preventDefault()
}
}
});
});
I used this in my case
but its better to use register_uninstall_hook
</div>