我制作了一个插件来发送每周新闻稿。目标是该插件将在每周一发送电子邮件。
我在这里有一些困惑:
1-请查看以下代码
function my_cron_definer($schedules){
$schedules['weekly'] = array('interval'=> 604800,
'display'=> __('Once Every week')
);
return $schedules;
}
add_filter('cron_schedules','my_cron_definer');
wp_schedule_event($timestamp, 'weekly', 'informantweeklynewsletter');
add_action('informantweeklynewsletter','informant_main_action');
所以,我把我的自定义递归设置为"每周"。然而,我不确定我应该为$timestamp
变量提供什么,这样无论插件何时激活,它都将从周一开始工作。在我的插件中,我没有定义任何激活和去激活的功能,因为我认为我不需要它们。
我的第二个问题是:wordpress cron不同于普通的cronjobs,因为它需要访问网站。看看上面的代码,我需要知道我的插件不起作用的可能性是什么。我能做出什么解决方案?每周一使用我的informant_main_action
方法。
谢谢
假设所有其他设置都正确。。。你可以使用
strtotime('nextmonday');
作为您的时间戳。你确实需要把它放在激活挂钩中,这样它只运行一次,你可以检查挂钩是否存在
if( ! wp_next_scheduled( 'informantweeklynewsletter' ) )
wp_schedule_event($timestamp, 'weekly', 'informantweeklynewsletter');
否则,每次有人访问你的页面时,你都会设置一个新的cron作业。。。。。
你可以用一个真正的cron工作来补充这一点,每周访问你的页面。如果你有cpanel,你可以使用这样的东西(注意你的路径必须更新)。*和数字是您希望它运行的时间,因此它的分钟、小时、天、月、工作日
* 2 * * 7 wget -O - http://yoursite.com/tasks.php >/dev/null 2>&