根据日期激活/取消激活插件

时间:2017-10-31 23:39:32

标签: php wordpress plugins

所以我在弄清楚如何将今天的日期与我选择的日期进行比较时遇到了一些问题。

这是我到目前为止所得到的!

function deactivate_plugin() {

// Full path to WordPress from the root
$wordpress_path = 'http://mainstaycomputing.com/';

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

// Absolute path to your specific plugin
$my_plugin = $plugin_path.'dw-halloween/dw-halloween.php';

// Check to see if plugin is already active
if(is_plugin_active($my_plugin)) {
    deactivate_plugins($my_plugin);
}
}
// trying to disable the plugin if past a certain date - in this case 
// halloween
if ( date("Y/m/d") == date(2017-01-11)) {
deactivate_plugin();
}

2 个答案:

答案 0 :(得分:0)

你可以这样做。 如果当前时间大于自定义日期,则停用插件。

$custom_date = "01/11/2017";
if (strtotime($custom_date) < time()){
      deactivate_plugin();
}

如果要在特定日期和时间后停用插件,也可以指定日期和时间     $ custom_date =“01/11/2017 23:59:59”;

如果此代码可以帮助您,请告知我们。感谢

答案 1 :(得分:-1)

我建议您使用strtotime()函数来比较PHP中的日期: http://php.net/manual/en/function.strtotime.php

$custom_date = "01/11/2017";
      if (strtotime("now") == strtotime($custom_date))
    {
      deactivate_plugin();
    }