Programmatically, I want to activate / deactivate a plugin of this specific blog/site in a WordPress Multisite. Any help will be gladly appreciated, thank you!
Asked
Active
Viewed 2,868 times
1
-
you don't need to network-activate the plugin on all sites in the main site - You can just install it, and activate it on the sub sites where needed – Stender Oct 17 '17 at 11:36
-
I am writing a plugin, so I need it programmatically. – Yves Oct 17 '17 at 12:57
-
you can deactivate it though a function for a specific site - if you have the ID for that site - or do you want a setting? – Stender Oct 17 '17 at 13:07
2 Answers
4
From your Network Dashboard go to any subsite dashboard
Then go to Plugins and activate plugin on this specific blog
In case you want to do it programmatically you can use activate_plugins() or deactivate_plugins() after a switch_to_blog( $blog_id ) function, example:
add_action( 'admin_init', 'true_plugin_off_in_theme' );
function true_plugin_off_in_theme() {
switch_to_blog( 'PASS_BLOG_ID_HERE' );
deactivate_plugins( 'true-instagram-widget/true-instagram-widget.php' );
restore_current_blog();
}

Misha Rudrastyh
- 866
- 10
- 16
-
-
-
How about for theme? **Programmatically Activate / Deactivate the theme of a Specific Blog** – Yves Oct 17 '17 at 15:12
-
1
-
3
Via WP-CLI
Reference: https://developer.wordpress.org/cli/commands/plugin/activate/
Syntax:
$ wp plugin activate [plugins...] --url=<url>
Usage:
- Activate Single Plugin:
$ wp plugin activate akismet --url="example.com"
- Activate Multiple Plugins:
$ wp plugin activate akismet jetpack ninja-forms --url="example.com"

Yves
- 807
- 15
- 17