admin管理员组文章数量:1201582
I'm trying to set up individual, one-time schedule events in a plugin. No matter what I do, I can't seem to get the events to fire. I'm using the Cron View plugin to see what's in queue, and the events are added and remove themselves totally on schedule. I never, however, receive the email I've set to send in the action's target function (simply in order to test the event, there will be more in there later). I have tested the function outside of scheduled events, it does work. Here's some code:
GLOBAL $new_workshop_id;
$new_workshop_id = $wpdb->insert_id;
function send_reminders() {
GLOBAL $new_workshop_id;
wp_mail('[email protected]', 'Automatic ID: '.$new_workshop_id, 'here it is!');
}
if (!wp_next_scheduled('send_reminder_emails_'.$new_workshop_id)) {
wp_schedule_single_event( time()+30, 'send_reminder_emails_'.$new_workshop_id );
}
do_action( 'send_reminder_emails_'.$new_workshop_id );
add_action( 'send_reminder_emails_'.$new_workshop_id, 'send_reminders' );
One thing I'm suspicious is the placement of do_acton and the function itself, send_reminders()
. The above code is within some if statements checking for POST vars, so it's possible that the function can't be accessed by the CRON job - so where should I put the function? I've tried right at the top of the plugin file. From what I've read, do_action should call the function and execute it wherever you have put do_action, but I guess I need to know where to put send_reminders()
in the first place so that it's accessible, by either the cron job or do_action.
Thanks in advance for any input!
I'm trying to set up individual, one-time schedule events in a plugin. No matter what I do, I can't seem to get the events to fire. I'm using the Cron View plugin to see what's in queue, and the events are added and remove themselves totally on schedule. I never, however, receive the email I've set to send in the action's target function (simply in order to test the event, there will be more in there later). I have tested the function outside of scheduled events, it does work. Here's some code:
GLOBAL $new_workshop_id;
$new_workshop_id = $wpdb->insert_id;
function send_reminders() {
GLOBAL $new_workshop_id;
wp_mail('[email protected]', 'Automatic ID: '.$new_workshop_id, 'here it is!');
}
if (!wp_next_scheduled('send_reminder_emails_'.$new_workshop_id)) {
wp_schedule_single_event( time()+30, 'send_reminder_emails_'.$new_workshop_id );
}
do_action( 'send_reminder_emails_'.$new_workshop_id );
add_action( 'send_reminder_emails_'.$new_workshop_id, 'send_reminders' );
One thing I'm suspicious is the placement of do_acton and the function itself, send_reminders()
. The above code is within some if statements checking for POST vars, so it's possible that the function can't be accessed by the CRON job - so where should I put the function? I've tried right at the top of the plugin file. From what I've read, do_action should call the function and execute it wherever you have put do_action, but I guess I need to know where to put send_reminders()
in the first place so that it's accessible, by either the cron job or do_action.
Thanks in advance for any input!
Share Improve this question edited Oct 21, 2010 at 20:32 Gavin asked Oct 21, 2010 at 20:24 GavinGavin 5372 gold badges6 silver badges11 bronze badges1 Answer
Reset to default 3The cron argument usage looks weird. The insert id will return garbage by the time your function is called.
By the same token, I believe better schedule it always, with the id argument, on insert, if this is for logging. Else you'll be throttling your logs, basically.
Lastly, are you sure that wp_mail()
is working?
本文标签: actionsScheduled event won39t fire
版权声明:本文标题:actions - Scheduled event won't fire 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738566298a2100213.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论