在 WordPress 中,我正在创建一个插件,用于向用户发送电子邮件。为此,我使用 WordPresscron
工作。所以基本上它要做的就是每小时向用户发送电子邮件。
所以我的代码看起来像这样
public function __construct() {
add_action('init', array( $this, 'send_emails_to_users') );
add_action('cliv_recurring_cron_job', array( $this, 'send_email') );
}
public function send_emails_to_users() {
if(!wp_next_scheduled('cliv_recurring_cron_job')) {
wp_schedule_event (time(), 'hourly', 'cliv_recurring_cron_job');
}
}
public function send_email() {
//send email code goes here
}
这里一切看起来都很好,但它不发送电子邮件。
如果我的代码是这样的
public function __construct() {
add_action('head', array( $this, 'send_email') );
}
然后它发送电子邮件。但问题在于,每次页面加载或用户访问网站时,它都会发送电子邮件。
这就是为什么我想使用wp_schedule_event
每小时发送电子邮件。
那么有人可以告诉我如何解决这个问题吗?
任何建议或帮助将不胜感激。
首先 ,
1)如果你想动态工作,你需要在你的服务器中设置crontab
2)如果你想手动,wordpress调度程序将在页面运行后调用
so,
对于 crontab 设置,下面是有用的链接:crontab http://code.tutsplus.com/tutorials/managing-cron-jobs-with-php-2--net-19428
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)