Can plugin2 uninstall plugin1 at the very beginning of plugin2’s installation?

On the register_activation_hook() function of the new plugin use the function deactivate_plugins() (or deactivate_plugin_before_upgrade()) and deactivate the older plugin and also delete the data with delete_option. If you will also delete the files, then use the function uninstall_plugin($plugin); maybe delete_plugins( $plugins, $redirect=”” )

Can my hooked uninstall class function access a global var declared in main plugin file?

The problem is that you aren’t declaring $dg_options as global here: define(‘DG_OPTION_NAME’, ‘document_gallery’); $dg_options = get_option(DG_OPTION_NAME); During uninstall you aren’t in the global scope, your file is being included by uninstall_plugin(). So you need to add this at the top of the main plugin file: global $dg_options; Really, any time you want a variable to … Read more

How to remove plugin-specific custom taxonomy terms when plugin is uninstalled?

You should be using the register_deactivation_hook and/or register_uninstall_hooks. That may be why some functions don’t work. I’d have to do some testing to be sure, but loading your method directly like WP_Plugin_Janitor::cleanup( $opt, $cpt, $tax ); seems like a pretty good way to skip over some of the WordPress load sequence or to run things … Read more