Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a plugin which creates some options in wp_options, but also creates custom post types and is used to populate that post type. Upon install it makes sense to remove the data in wp_options, but with regards to the populated post type, there should be an option for the user to choose whether he wants to keep that data or not.

Ideally I would like a popup when he hits the uninstall link, asking if he wants to delete just the plugin files and options, or delete everything. How can I do such a popup?

share|improve this question
    
register_uninstall_hook() should do the trick. –  kaiser Sep 19 '12 at 17:03
    
I'm looking for a specific example on how to create this popup. –  drtanz Sep 19 '12 at 18:34
    
    
@drtanz Why don't you use an admin pointer? Look here: wordpress.stackexchange.com/a/46567/9579 –  Michael Ecklund Sep 24 '12 at 15:52
    
@MichaelEcklund Admin Pointers in a theme won't pass the "Theme Checker" plugin. –  kaiser Sep 25 '12 at 14:59
show 1 more comment

2 Answers

up vote 3 down vote accepted
+25

How about something similar to this:

function wpse65611_script() {
    wp_enqueue_style( 'wp-pointer' );
    wp_enqueue_script( 'wp-pointer' );
    wp_enqueue_script( 'utils' ); // for user settings
?>
    <script type="text/javascript">
    jQuery('#embed-github-gist .delete a').click(function(){
            jQuery('#embed-github-gist .delete a').pointer({
                content: '<h3>Delete this or delete everything?</h3><p><a id="this" class="primary button" href="url1">Delete data</a> <a id="everything" class="button" href="'+jQuery('#embed-github-gist .delete a').attr('href')+'">Delete plugin</a></p>',
                position: {
                    my: 'left top',
                    at: 'center bottom',
                    offset: '-1 0'
                },
                close: function() {
                    //
                }
            }).pointer('open');
return false;
        });
    </script><?php
}
add_action( 'admin_footer', 'wpse65611_script' );

Which results in this:

enter image description here

Replace url1 with the url that would delete just the data.

Note that this will not run if you put it in the plugin and the plugin is deactivated, putting it in another plugin or in a theme would work but it would be bad practice

Also replace the ID of the embed github gist plugin with your own

share|improve this answer
    
The actual popup should appear on the next screen, where the user gets the choice. I'm actually thinking that this will be overall too confusing for a user. I haven't seen any other plugin doing this and since I'm still quite inexperienced maybe it's better to do things the normal way and avoid this altogether. –  drtanz Sep 25 '12 at 19:06
    
That's because in order for you to insert the extra choice your plugin needs to eb activated, and for you to be able to even get to that screen your plugin must be deactivated. Thus it is impossible for a plugin to modify its own delete plugin confirmation screen without outside help –  Tom J Nowell Sep 25 '12 at 19:08
    
But if you really must, just take the selector used and modify it so that it's the selector for the confirmation button link –  Tom J Nowell Sep 25 '12 at 19:08
3  
Imagine you're trying to demolish a house and you want to add a button that removes all your stuff before it blows up, but to do that you need to be inside the house when it gets demolished –  Tom J Nowell Sep 25 '12 at 19:10
add comment
function wpse65611_confirm_uninstall()
{
    ?>
    <form>
        <input type="button" onclick="wpse65611_confirmation()" value="Delete Data?">
    </form>
    <?php
}

function wpse65611_script()
{
<script type="text/javascript">
    function wpse65611_confirmation()
    {
        var answer = confirm( "Delete Data?" );
        if ( answer )
        {
            window.location = "<?php admin_url( 'plugins.php?delete=data' ); ?>";
        }
        else
        {
            window.location = "<?php admin_url( 'plugins.php' ); ?>";
        }
    }
</script>
}
add_action( 'admin_footer', 'wpse65611_confirmation' );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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