• Resolved michael3384

    (@michael3384)


    Hey! I’m working on a plugin that creates a table and sets some options. When you deactivate the plugin via ‘site admin -> plugins’ I’m fine with it leaving the table in the database but I want to at least provide the possibility of completly uninstalling the plugin, meaning dropping the table, deleting the options and deactivating the plugin.
    I set up an options page with a link to uninstall the plugin. It calls the following function that I copied from another plugin. It doesn’t seem to work right and I have problems understanding the code (by the way, where do I find some kind of developer documentation? I would help if it isn’t set up already but I think it’s a very important thing to have. The one here on the site, is that the one? Not complete at all, isn’t it?).

    This is the function that’s supposed to uninstall the plugin:

    function myplugin_plugin_uninstall() {
    global $table_prefix, $user_level;
    if ( $user_level >= 10 ) {
    // Drop MySQL Tables
    $SQL = "DROP TABLE ".$table_prefix."myplugin";
    mysql_query($SQL) or die("An unexpected error occured.".mysql_error());
    // Delete Option
    delete_option('myplugin_config');
    // Deactivate Plugin
    $current = get_settings('active_plugins');
    array_splice($current, array_search("myplugin.php", $current), 1 );
    update_option('active_plugins', $current);
    $redirect_url = wp_nonce_url("plugins.php?action=deactivate&plugin=myplugin.php", 'deactivate-plugin_myplugin.php');
    header('Location: '.$redirect_url);
    die();
    }
    }

    What is e.g. wp_nonce_url?

    When I click the uninstall button on my options page a site loads aksing me, if I really wanna deactivate the plugin named “”. I click yes and another page loads asking me if I want to really deactivate the plugin named “myplugin”. I click yes and the plugin deactivated but neither the table is dropped nor the options deleted. What am I doing? What am I doing wrong?

    Thanks alot for you help!! I hope this is the right place to post this, if not, where?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Regarding the documentation bits:
    Have a look at the links under “Extending” at the Developer_Documentation page. Among others, that will link to Writing_a_Plugin.

    You might also have a go at the WP Hackers Mailing List for specific questions: https://codex.www.ads-software.com/Mailing_Lists#Hackers

    Thread Starter michael3384

    (@michael3384)

    Thank you!

    I just solved most of my problem: I put $wpdb to the globals. Now the table is droped, the options deleted and the plugin deactivated. So, there we go!

    I still don’t get why the two pages load, asking me, if I really want to deactivate the plugin. The first one doesn’t even say which one. Can someone explain this to me please?

    Thanks alot!

    Thread Starter michael3384

    (@michael3384)

    Alright, now I got what I wanted. I droped the $redirect_url and changed header('Location: '.$redirect_url); to header('Location: plugins.php?deactivate=true'); Thanks for listening folks! You’re great!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Drop table, delete options, deactivate plugin’ is closed to new replies.