admin管理员组文章数量:1287515
In the current version of my plugin, I create a page on install, and remove it on uninstall. In a new, planned version, I've refactored such that I no longer need that page anymore. When a user upgrades to the new version, will WordPress run the uninstall function before upgrading and then does it run the install on every upgrade, as opposed to only on new installations?
If I remove the uninstall function in the new version (as it's not needed anymore), will users of the old version get an orphaned page with no code which will ever clean it up? In which case, should I leave the code to remove the page, forever?
I'm looking for insight on the WordPress plugin upgrade lifecycle, thanks.
In the current version of my plugin, I create a page on install, and remove it on uninstall. In a new, planned version, I've refactored such that I no longer need that page anymore. When a user upgrades to the new version, will WordPress run the uninstall function before upgrading and then does it run the install on every upgrade, as opposed to only on new installations?
If I remove the uninstall function in the new version (as it's not needed anymore), will users of the old version get an orphaned page with no code which will ever clean it up? In which case, should I leave the code to remove the page, forever?
I'm looking for insight on the WordPress plugin upgrade lifecycle, thanks.
Share Improve this question asked Sep 20, 2021 at 7:15 T NguyenT Nguyen 1133 bronze badges 1- Why don't you just run your uninstall using a conditional check? IF the page is there, run the uninstall, if it isn't, skip past it. That way you're ensuring that you're making things backwards compatible for users of the older version. – Tony Djukic Commented Sep 21, 2021 at 14:45
1 Answer
Reset to default 1No, the activation, deactivation and uninstall hooks will not be run when the plugin is updated.
So when your plugin is updated the page will still be there (assuming the user has not deleted it), and it will not be deleted on uninstall if your plugin no longer does this on uninstall.
If you want to do something on update, the proper way is described here:
The proper way to handle an upgrade path is to only run an upgrade procedure when you need to. Ideally, you would store a “version” in your plugin’s database option, and then a version in the code. If they do not match, you would fire your upgrade procedure, and then set the database option to equal the version in the code.
You could then delete the page in question in that upgrade procedure.
本文标签: Does WordPress run installuninstall functions on plugin upgrade
版权声明:本文标题:Does WordPress run installuninstall functions on plugin upgrade? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741311141a2371655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论