什么都没有让我的register_activation_hook工作

时间:2017-10-10 01:45:48

标签: php wordpress plugins hook activation

好的,我一直在寻找解决方案。出于某些不明智的原因,我无法找到正确的解决办法,我真的不明白出了什么问题。

我正在尝试使用register_activation_hook和register_deactivation_hook。这是我的代码。

register_activation_hook(__FILE__, 'plugin_on' );
register_deactivation_hook(__FILE__, 'plugin_off' );

function plugin_on() {

    $file = 'people.txt';
    // Open the file to get existing content
    $current = file_get_contents($file);
    // Append a new person to the file
    $current .= "1\n";
    // Write the contents back to the file
    file_put_contents($file, $current);

    wp_schedule_event( time(), 'minutely', 'my_daily_event' );
}

add_action( 'my_daily_event',  'mail_test' );

function plugin_off() {
    wp_clear_scheduled_hook('my_daily_event');
}
永远不会调用

plugin_on。

以下是我已经尝试的一些事情,或者我知道的事情不是问题。

  1. 我的插件文件夹没有符号链接。
  2. 打开网站的主页时,肯定会调用此文件。
  3. __FILE__路径是正确的。它指向此文件,这是主插件文件。
  4. 非常感谢任何帮助。

0 个答案:

没有答案