用于在wordpress中激活插件的代码

时间:2012-09-19 08:56:07

标签: wordpress plugins

这个客户希望在几个小时之后每周二自动激活一个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

1 个答案:

答案 0 :(得分:0)

  

在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' );