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.


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


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).


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.