When my plugin is deactivated, I want to get a confirmation from the user whether all plugin options/tables need to be deleted or left as it is. Based on the option selected, I want to proceed further. Is it possible ? If yes, how ?

  • 2
    Yes it is possible but don't confuse deactivation for uninstall. They are two very different things. You actually don't want to delete anything when a plugin is deactivated. When they uninstall is when you want to ask the user if they want to delete settings. Look into the register_uninstall_hook – user23654 Sep 5 '13 at 13:54
  • There is a discussion here which doesn't directly answer your question but will certainly help with your question: wordpress.stackexchange.com/questions/25910/… – Matt.C Sep 5 '13 at 13:58
  • @Matt.C Yes, I have gone thru the link but did not serve my purpose. Thanx though :) – Navin Nagpal Sep 5 '13 at 14:26

I have implemented a workaround with JavaScript. I'm loading my own JavaScript file:

wp_enqueue_script('wp-deactivation-message', plugins_url('js/message.js', dirname(__FILE__)), array());

which contains a script that adds following Event Listener - when user clicks on our plugin deactivate button it prevent it from performing this action and display a JavaScript popup asking what you need, if user accepts it will be deactivated, if user press 'cancel' nothing happens:


window.onload = function(){
        document.querySelector('[data-slug="plugin-name-here"] a').addEventListener('click', function(event){
            var urlRedirect = document.querySelector('[data-slug="plugin-name-here"] a').getAttribute('href');
            if (confirm('Are you sure you want to save this thing into the database?')) {
                window.location.href = urlRedirect;
            } else {
                console.log('Ohhh, you are so sweet!')
| improve this answer | |
  • document.querySelector('[data-slug="plugin-name-here"] a') is not perfect, there could be more than one links inside the div with data-slug, like deactivate, delete or more. It should be more like: document.querySelector('[data-slug="plugin-name-here"] .deactivate a') – Jamal Khan Mar 2 at 9:46

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.