I'm building two mutually incompatible plugins. When either one is activated, the other must be deactivated. I'm using the code below to accomplish this.
It works fine the first time I upload and activate the second plugin, but if I try to activate the inactive plugin in the admin panel, it just deactivates both plugins. (Though I get a confirmation message saying "plugin activated." Liars!) I am then able to activate either one of the two plugins.
Any ideas what the problem is?
function deactivate_other_plugin() {
if( is_plugin_active('plugin_folder/plugin_file.php') ) {
deactivate_plugins('plugin_folder/plugin_file.php');
}
}
add_action( 'admin_init', array( $this, 'deactivate_other_plugin' ) );
&$this
is a hack to make things work on PHP4, you should use$this
instead when registering functions as is customary in PHP 5 ( unless your plugin is aimed for a server stack from 2003 and WordPress v1.5 )