Auto Deactivate a Plugin on Another Plugin Activation

By Tejaswini Deshpande | May 19, 2014

It is sometimes needed to deactivate a certain plugin while your plugin is being activated. The reason for it can be anything, like if two plugins are incompatible or if you are providing premium version of a free or lite plugin. So while activating the premium version you can automatically deactivate the free or lite version in the activation hook of the premium plugin.

You should be using some code similar to

register_activation_hook( __FILE__, 'install_premium_version' );

in your plugin code.

You should put the deactivation code inside the ‘install_my_plugin’ function as follows:

if( is_plugin_active('lite-version/lite-version.php') ){
     add_action('update_option_active_plugins', 'deactivate_lite_version');

where ‘lite-version/lite-version.php’ is the plugin name(main plugin file).

Include the ‘deactivate_lite_version’ function below the activation hook line as

function deactivate_lite_version(){

This is how you can your one plugin will auto deactivate another installed and active WordPress plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *