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
Add a comment  | 

1 Answer 1

Reset to default 1

No, 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