1

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.

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. Sep 21 at 14:45
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.

1
  • I see, so I would have to manually store and track version in able to identify an "upgrade" event and then manage the proper cleanup? Sheesh, seems to me like this is exactly the kind of task a framework should handle and simply give us a hook for when a plugin is upgraded.
    – T Nguyen
    Sep 21 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.