Deletion of shared options using uninstall.php
-
29-09-2020 - |
Question
I'm using uninstall.php
for my plugin to delete all the traces my plugin did to a site on uninstall (delete). I did it in a good way, but even after the deletion there are some fields in the options
table:
uninstall_plugins
recently_activated
_site_transient_update_plugins
in these options there are multiple values from other plugins too.
How can I take care of such traces, how can I remove all those traces too?
I checked WooCommerce and found they leave no traces after there deletion, if the "delete data" checkbox is checked.
How can I do so?
Solution
I don't think that you should touch these options. WordPress core already handles this, whether by removing the references to your plugin when it is deleted (as in delete_plugins()
), or by being coded in such a way that it can ignore the reference to the removed plugin. Actually, none of these three options will last very long, since they are all regenerated regularly. The one is a transient, which naturally expires anyway. The plugins are removed from the recently activated list after a week. And the plugin is removed from the uninstall_plugins
option by uninstall_plugin()
.
Also, WooCommerce doesn't touch these. It probably just looked like it removed itself because it was never added to these values in the first place, or was removed that quickly by WordPress. (It wouldn't have been added to uninstall_plugins
at all, because it uses an uninstall.php
file instead of a function).
So, TL;DR: You don't need to worry about this, WordPress will take care of it.