This going to be my last post on the issue uninstallers for WordPress plugins. This is an explanation of the code I have submitted to the WordPress trac, and a plugin to give you an idea of what it does differently to the previous two versions I produced.
I think it is important to note that although I have submitted this code for inclusion in the core, that doesn’t mean it will be included exactly as I submitted it, or even that it will be included at all, but I am hopeful.
In the first version a separate file was required, but it was fairly evident that this wasn’t going to be the best solution. The second version changed this, allowing the plugin author to register a callback function, and added functions to help ringfence the uninstall content from the live plugin content.
In the final version not even this is necessary.
The most important function in version three is register_plugin_assets(). This function, used in an activation function allows the plugin author to register the options they intend to add to WordPress, the database tables they intend to add, and to register a callback function within the plugin itself.
[php]
register_plugin_assets( $plugin_file , $callback , $options = array() , $tables = array() );
Registering the tables and options lets WordPress take care of uninstalling those, meaning that the plugin author doesn’t need to write any code at all to handle uninstallation unless it requires more complex changes or file deletions. In many cases $callback can be set to NULL.
If a callback function is registered, before the tables and options are removed, the plugin will be loaded to allow the callback function to be used. There is no longer a need to ringfence that code; however, it will mean that plugin authors need to be careful about what their plugin does that isn’t triggered by a hook.
On the surface the process works the same. When a plugin is deactivated, and there is something to uninstall, the uninstall option will be presented beneath the plugin entry. Although, the discussion on the trac is that it may be in a table column of its own I have left it as per previous versions as that is what I actually submitted and because of the limitations of doing it as a plugin.
You can download Fun with Uninstallation 0.3 here.
The plugin is as close to the code I submitted. As it was written for the version of WordPress currently in development I haven’t done much testing on it outside of that. The version I tested the plugin on was 2.3.2.
(__)
`
wesley
Well, some people might still want to use it for backwards compatability with older wp versions. Never mind though, as I see the source code in the trac. Thanks
(__)
`
Andrew Rickmann
Wesley,
The downloads have been removed because they are not relevent any more. The patch I submitted has been completely changed. Uninstallation for plugins will be available as part of the delete process in WP 2.7 a version of the plugin generator that supports it will be released soon.
I also found some people were misunderstanding the point of the plugins. It was to illustrate an idea but had no practical value outside that. Some people thought it would clean out their plugin settings for plugins they didn’t want any more.
(__)
`
wesley
None of your downloads work (v1, 2, 3)