Is it possible to run javascript on plugin deactivated?

Is it possible to run javascript on plugin deactivated and if yes then, how should I achieve that. I have developing one plugin in which two new tables are created in wp database and on deactivation I want to confirm from users if he/she wants to delete those table before deactivating.

Topic deactivation plugin-development plugins Wordpress javascript

Category Web


It is impossible to do. Deactivation is not always triggered from any UI, therefor you can't assume that you will be able to ask the user for any kind of confirmation.

Anyway deactivation is the wrong place to do such things, you might consider such cleanup on uninstall.

A thing you can do is to configure the uninstall behaviour in the plugin's configuration/options screen, but it is unlikely to be a good UX, just a lesser evil.


In your plugin you can define a deactivation hook. You can activate your script with the function you hook there (or perhaps you won't need javascript at all and can achieve what you want with php).


This is really a javascript question, but there is nothing preventing you from doing a regular confirm with AJAX.

For example: https://stackoverflow.com/questions/8680491/javascript-confirm-with-php-function-afterward

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.