结合使用switch_to_blog()
, activate_plugins()
, 和deactivate_plugins()
.
您可以将其放入函数中。php,但您希望在它运行后将其删除:
// hook to admin init
add_action(\'admin_init\', \'wpse_swap_plugins\');
function wpse_swap_plugins() {
// set blog ID per your needs
$blog_id = 3;
// switch to the site where you want to activate/deactivate plugins
switch_to_blog($blog_id);
// activate: set your path, don\'t set redirect,
// don\'t make this network wide, don\'t prevent activation hooks
activate_plugins(array(
\'/full/path/to/plugin/you/want/to/activate.php\'
), \'\', false, false);
// deactivate: same arguments as activate
deactivate_plugins(array(
\'/full/path/to/plugin/to/deactivate.php\'
), \'\', false, false);
// switch context back to original site
restore_current_blog();
}
相关答案得分:
Deactivate plugin for a specific user group