Drop table, delete options, deactivate plugin
-
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?
- The topic ‘Drop table, delete options, deactivate plugin’ is closed to new replies.