What triggers the WordPress register_uninstall_hook()?

I spent over an hour trying to figure out the user’s workflow when wanting to add an uninstall hook to a WordPress plugin. I did eventually stumble across the answer, which once you know probably seems blatantly obvious. However, it wasn’t for me at the time.

Question: How to trigger theĀ register_uninstall_hook() callback function?

Answer: Delete the plugin!

I spent a lot of my time looking for the uninstall link. Wondering if I was supposed to make my own. Not sure whether it being a Network Activated plugin made a difference. All the documentation and blog posts I could find just implied that it would all work out of the box. And, well, it does.

Delete Plugin And DataWhen you deactivate and then delete a plugin, it usually asks you for confirmation. With a plugin that has registered and uninstall hook, it adds some additional text. Personally I think that’s a little obfuscated, both to developers and to users. Maybe I’ll find the time to figure outĀ tracĀ andĀ submit a patch for recommending further emphasis. Hopefully, I will find somewhere to mention it on the wordpress.org documentation site.


Published by


Open Source Architect (Web Geek)