WordPress MultiSite:以编程方式激活/停用特定博客的插件

时间:2017-10-17 作者:Yves

以编程方式,我想在WordPress多站点中激活/停用此特定博客/站点的插件。我们将非常感谢您的帮助,谢谢!

2 个回复
最合适的回答,由SO网友:WebElaine 整理而成

结合使用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

SO网友:Yves

Via WP-CLI

参考号:https://developer.wordpress.org/cli/commands/plugin/activate/

Syntax:

wp plugin activate <plugin(s)> --url=<url>
<小时>

Example:

  1. wp plugin activate akismet --url="foo.example.com"
  2. wp plugin activate akismet jetpack ninja-forms --url="bar.example.com"

结束

相关推荐

在WordPress MultiSite中创建默认页面

新网站创建时,我正在努力创建WordPress多站点页面。我找到了一些钩子来实现这一点,但钩子没有响应。我在stack和其他网站上找到的一些资源是https://stackoverflow.com/questions/40014419/wordpress-multisite-default-page-for-newly-created-site 和http://www.wpbeginner.com/wp-tutorials/how-to-add-remove-default-pages-in-wordpr