views:

15

answers:

2

Following some examples, I have a function that gets triggered on the 'register_deactivation_hook'.

This functions drops the DB created on activation.

My question is: Is it good practice to DROP the table on de-activation?

I might want to de-activate it to test something and it would be annoying to loose all my data in that table.

Dropping a table seems more appropriate to do of you want to delete a plugin. I'm not sure if there is a hook for this though.

+2  A: 

This is a bad idea!!!

If you manually update a plug-in via PHP (some people still do), you're supposed to deactivate it before transferring files. You might also deactivate a plug-in to test the configuration of your site. Dropping the plug-in's database tables every time you deactivate will cause you to lose your data!

Most plug-ins that create custom DB tables and entries have a separate "Uninstall" operation. It's a button on the admin page or a link under the plug-in name on the Plugins page. Clicking "Uninstall" will remove the DB table and then deactivate the plug-in. This is a much safer way to do things.

You're right, there is no register_deletion_hook ... so this is the best, most common, and easiest way to handle a full plug-in uninstallation. Please don't ever use register_deactivation_hook to drop a DB table ...

EAMann
That's what I suspected. There is the normall `Delete` function in the plugin list. But it's not this one you mean for Uninstall? I should add my own "Uninstall" link?
Steven
The `Delete` function will remove your plug-in's files ... and you can't hook on to it. You should add your own `Uninstall` link that both cleans up the database and then deactivates the plug-in ... deletion after that would be up to the end user.
EAMann
+1  A: 

Use a uninstall.php file. see here -> http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.7#Uninstall_Plugin_API

Darren