Does WordPress run install/uninstall functions on plugin upgrade?

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.

Topic upgrade plugin-development Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.