Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Multisite - how to automatically deactivate another plugin? WordPress

I am the developer of Leaflet Maps Marker Plugin ( and I am currently working on a pro version which will be a separate plugin (/leaflet-maps-marker-pro/) and cant be active together with the free version (/leaflet-maps-marker/)

In order to achieve this, I added the following code on top of the pro version core file:

include_once( ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php' );
if (is_plugin_active('leaflet-maps-marker/leaflet-maps-marker.php') ) {
activate_plugin('leaflet-maps-marker-pro/leaflet-maps-marker.php', $redirect = 'plugins.php?activate=true');

This works fine on single site installation but fails on multisite. If fails on multisite if the free version is activated network wide and if the free version is active on a subblog only.

Therefore I tried the following:

if (is_plugin_active('leaflet-maps-marker/leaflet-maps-marker.php') ) {
global $wpdb;
$blogs = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = {$wpdb->siteid} AND spam = 0");
if ($blogs) {
foreach ($blogs as $blog_id) {
deactivate_plugins('leaflet-maps-marker/leaflet-maps-marker.php', true); //silently deactivate the plugin
?><div id="message" class="updated fade"><p><span style="color:#FF3300;">Plugin</span><?php _e(' has been MASS DEACTIVATED.', 'pm'); ?></p></div><?php
} else {
?><div class="error"><p><?php _e('Failed to mass deactivate: error selecting blogs', 'pm'); ?></p></div><?php

Didnt work either. I would need the free version to be deactivated on all blogs (including the main one!) if the pro version gets activated as otherwise the user would get errors.

Can anyone tell me how to best achieve this?

Answers (4)


Yakir Sitbon answers:

I don't know about deactivate plugin and activate another one, but I think you can "disable" access to your plugin with MultiSite, And put "Error" notification for upgrade to pro plugin.

What you think about this idea?

[Nice to see you again. =)]

Robert Seyfriedsberger comments:

thanks, but that is unfortunately not an option due to other reasons...



Go to the Plugins => Add New page.
Enter 'Plugin Options Starter Kit' (without quotes) in the textbox and click the 'Search Plugins' button.
In the list of relevant Plugins click the 'Install' link for Plugin Options Starter Kit on the right hand side of the page.
Click the 'Install Now' button on the popup page.
Click 'Activate Plugin' to finish installation.
That's it!

Robert Seyfriedsberger comments:

thx but I need a code I can use in my plugin without users having to install another plugin...


Before beginning
make a backup copy of your database.

see here:====================
Backing up your database as often as possible is essential. For WordPress, as well as for other applications, plugins and other scripts that help automate the task are easily obtainable. However, for several reasons, it is a good idea to understand the process of manually creating a backup copy of your database. This brief tutorial1 should help cement the process into a solid reference. We are assuming that you have an SQL database and have access via phpMyAdmin.

Before reading through the gory details written below, check out the screenshot to the left (click on the image). That picture is literally worth a thousand characters. Another way to avoid the forthcoming verbose explanation is to skip the next paragraph to the neatly summarized list.

First, open phpMyAdmin and select from the dropdown menu the database you wish to backup. If there is only one database available, select it by clicking on its name. Now, along the upper-right row of tabs, click on the "export" tab. From that screen, under the subcategory "Export", click on "select all" and make sure that the "SQL" option is selected. Then, under the SQL Options/Structure category, make sure "Structure", "Add DROP TABLE", "Add AUTO_INCREMENT value", and "Enclose table and field names with backquotes" are checked. Finally, under the "SQL Options/Data" category, make sure "Data", "Complete inserts", and "Use hexadecimal for binary fields" are checked. The "Export type" should be set to "INSERT". Finally, check "Save as file" and do not change the "File name template". It is advisable to save both a compressed copy and a zipped copy. Click "Save" and you are done.

Open phpMyAdmin, select database, click on "Export"
Within the "Export" screen, click on "Select All" and select "SQL"
Then check "Structure", "Add DROP TABLE", "Add AUTO_INCREMENT..", and "Enclose table.."
Also check "Data", "Complete inserts", and "Use hexadecimal.."
Check "Save as file", select a compression format, and "Go"!

login to your database using phpMyAdmin (or whatever), and navigate to the “active_plugins” column of the “wp_options” table using the following SQL query (edit the default WordPress table prefix “wp_” if needed):

SELECT * FROM wp_options WHERE option_name = 'active_plugins';

Once the active_plugins column appears, click to edit it. You will see something similar to the following, depending on the number and type of plugins you have installed:


That entire array of code represents every active plugin on your site. Thus, to quickly disable all plugins without using the WP Admin area, highlight the entire block of code, cut it out, and paste it into a safe, offline text file. After removing the code, click the button to save your changes and that’s it. All WordPress plugins are now deactivated (yet still installed, and with all plugin options intact). This obviously is a huge time-saver that really comes in handy during those mission-critical, time-sensitive situations where every second counts. Once you are ready to re-activate your entire set of plugins, simply cut/copy & paste the preserved code back into the “active_plugins” field. Click save and done. Again, don’t forget to backup your database before editing it ;)

Alternately, here is a one-second query to disable all plugins:----------------------------------------

UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';

Upon execution, this query will clear the active_plugins field of all active plugins (duh), effectively disabling (without uninstalling or modifying) the entire set. This method is great if you plan on re-enabling each plugin individually, say, after resolving some heinous server error. Whereas the previous technique makes it easy to re-enable all plugins en masse, this query is perfect for simply “nuking” all active plugins with no remorse. ;)

Updated Method========================

Apparently, this method works only for WordPress versions less than 2.9. For 2.9 and better, use this instead:

UPDATE wp_options SET option_value = 'a:0:{}' WHERE option_name = 'active_plugins';

So use that if working with WP2.9 or beyond!

I hope your problem solve If you follow my post.


Robert Seyfriedsberger comments:

thx again. Unfortunately this is also not what I need - only my free plugin should be deactivated when the user activates the pro version. This means the solution must work automatically especially for users who only activate plugins through the network admin setting without touching any code...


Daniel Yoen answers:

Hello, you can try this :

add_filter('site_option_active_sitewide_plugins', 'node_deactivate_plugins');

function node_deactivate_plugins($value)

return $value;

hope this help :-)

Daniel Yoen comments:

also you can read this :


Giri answers:

Just use filters to disable old plugin.


add_filter('option_active_plugins', 'maps_marker_activation');

add_filter('site_option_active_sitewide_plugins', 'maps_marker_activation');

function maps_marker_activation($value) {

if (is_plugin_active('leaflet-maps-marker/leaflet-maps-marker.php') ) {
return $value;

Then proceed with plugin activation as usual.