admin管理员组文章数量:1122846
I recently heard from a support team for a particular plugin which shall go unnamed:
You are right, (our plugin) does not clean the tables upon deleting the plugin. If you really want to remove all the table upon deletion, you may use a plugin to clean your database.
We do not remove the table data for security purposes in case if you come back to the plugin again, you can continue from where you left it."
It would seem to make more sense to keep the tables intact upon deactivation, but delete them upon pluin removal/deletion.
Is there a difference between the deactivation action vs the deletion action technically, such that the above logic would work? I.e., can the plugin "know the difference" wheter it's being deactivated vs deleted?
And if so, how could that be implemented (generally)?
I recently heard from a support team for a particular plugin which shall go unnamed:
You are right, (our plugin) does not clean the tables upon deleting the plugin. If you really want to remove all the table upon deletion, you may use a plugin to clean your database.
We do not remove the table data for security purposes in case if you come back to the plugin again, you can continue from where you left it."
It would seem to make more sense to keep the tables intact upon deactivation, but delete them upon pluin removal/deletion.
Is there a difference between the deactivation action vs the deletion action technically, such that the above logic would work? I.e., can the plugin "know the difference" wheter it's being deactivated vs deleted?
And if so, how could that be implemented (generally)?
Share Improve this question asked Apr 7, 2024 at 20:39 DrewdavidDrewdavid 2191 silver badge12 bronze badges2 Answers
Reset to default 1Yes, there is a difference and it is possible for a plugin to know when it is deactivated or deleted.
For deactivation the plugin may register a deactivation callback using register_deactivation_hook()
.
For deletion the plugin may either register a deletion callback using register_uninstall_hook()
or include a uninstall.php
file in its base folder. There's an important note on the function reference about using the file method,
This file will be called, if it exists, during the uninstallation process bypassing the uninstall hook. The plugin, when using the ‘uninstall.php’ should always check for the ‘WP_UNINSTALL_PLUGIN’ constant, before executing.
Sidenote: What I've seen over the years is that most plugins don't bother doing any cleanup when they are deactivated or deleted leaving behind for example a settings mess in the options
table or scheduled WP cron hooks. Some plugins do the cleanup without telling you about it while a few have explicit settings that lets the user decide should the plugin data or tables be removed or not.
The differenc between inactive and deleted plugin is kinda semantic. If the plugin is not active why should there be any data kept in DB about it? Ofcourse life is not black and white and a user might want to deactivate a plugin for a short while and reactivate it later in which case deleting data is a no-no.
The problem with how wordpress manages plugins is that there is at least one state missing, call it "maintenance" or "suspended".
The reality of uninstalling is that the plugin might not have enough context at that point as the plugin is not fully running and without the context it might not know how to delete all the data. More than that deletion might take more time than is available when handling one http request.
and then there are users that delete a plugin just to reinstall it again (maybe your plugin has some of them)
I think I saw some plugins with the option to delete their data which might make the most sense.
In the end it boils down to wordpress core not defining the expected state of the data after deactivation and deletion which creates this mess as users do not have a defined expectations and will ask for contradicting things from plugin authors.
本文标签: Can plugin authors make db tables remain upon deactivationbut be removed upon plugin deletion
版权声明:本文标题:Can plugin authors make db tables remain upon deactivation, but be removed upon plugin deletion? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309822a1934155.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论