2

该客户希望在每周二几个小时之间自动激活一个 wordpress 插件。这是因为该插件与另一个插件有冲突。我在网上没有找到任何关于此的内容,该怎么做...任何人都知道当单击按钮激活插件时 wordpress 背后会发生什么?我在我的 wordpress 文件夹中找不到该特定页面...谢谢!

我尝试过但不起作用的东西:

require('/web/htdocs/www.fattorefamiglia.com/home/wp-content/plugins/quick-chat/quick-chat.php');

function toggle_plugin() {

    // Full path to WordPress from the root
    $wordpress_path = '/web/htdocs/www.fattorefamiglia.com/home/';

    // Absolute path to plugins dir
    $plugin_path = $wordpress_path.'wp-content/plugins/';

    // Absolute path to your specific plugin
    $my_plugin = $plugin_path.'quick-chat/quick-chat.php';
$start = strtotime('1:30');
$end = strtotime('22:30');
$timenow = date('U'); 

if((date('w') == 3) && ($timenow >= $start && $timenow <= $end)) { // day 2 = Tuesday
     activate_plugin($my_plugin);
    }
    else {
        deactivate_plugins($my_plugin);   
    }
} 

我把这段代码放在functions.php中

4

1 回答 1

2

在 wordpress 中通过代码激活插件

  function run_activate_plugin( $plugin ) {
     $current = get_option( 'active_plugins' );
     $plugin = plugin_basename( trim( $plugin ) );

     if ( !in_array( $plugin, $current ) ) {
     $current[] = $plugin;
      sort( $current );
      do_action( 'activate_plugin', trim( $plugin ) );
      update_option( 'active_plugins', $current );
      do_action( 'activate_' . trim( $plugin ) );
      do_action( 'activated_plugin', trim( $plugin) );
     }

    return null;
  }
run_activate_plugin( 'plugin-folder-name/plugin-main-file.php' );
于 2016-07-09T11:28:08.587 回答