Closed liedekef closed 1 year ago
Typically, a plugin has to be deactivated before it can be uninstalled. If the update checker is set up as part of a plugin (which seems to be the case here since you're using the __FILE__
constant), it would not be running when the plugin is deactivated, and it would be impossible for it to trigger any errors.
Do you have any ideas about how the update checker code could be executed while the plugin is being deleted?
I'm just using the code in my main plugin file as you say in the doc. See https://github.com/liedekef/events-made-easy/blob/main/events-manager.php
Right, so how is the code in your main plugin file running when the plugin is inactive? Does the plugin have an uninstallation script (uninstall.php
) or something that also loads the main plugin file?
There is an uninstall.php and indeed there I load the main plugin file (because all other code/functions/defines are done from the main file). I'm in fact re-using the function that handles the plugin deactivation to also delete the tables, options and cron-definitions. Loading the main plugin file gives me access to all the constants, functions and more needed to do a clean uninstall. So I now understand a bit more of the reason behind this. I'm guessing the WP_UNINSTALL_PLUGIN-check is then ok to use, since it is probably only defined when uninstall.php is being run.
All right, that makes sense. The update checker has some built-in safeguards that automatically remove its hooks when using an uninstallation hook, but those don't work with uninstall.php
. In this case, you would need to either completely avoid initializing the update checker when the plugin is being uninstalled, or call $myUpdateChecker->removeHooks()
inside your uninstallation script.
Technically, WP_UNINSTALL_PLUGIN
will be defined when any plugin that has an uninstall.php
file is being uninstalled, but I don't know if it's worth worrying about that in this case.
Thanks for the clarification. I'm currently splitting out the code a bit more, so I can include another file that doesn't trigger the update-functions (and more), so in fact it should be much better after that :-)
When a plugin using plugin-udate-checker is being uninstalled, it triggers a php error:
Currently I worked around this by changing the recommended code in my main plugin file from:
to:
So, in fact checking if not in uninstall mode. But this should probably be done better and inside the plugin update script itself I guess, no? Is this even a recommended method?