WordPress中的Cron工作无法正常工作 [英] Cron job in WordPress not working

查看:72
本文介绍了WordPress中的Cron工作无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个WordPress cron作业,应该每小时发送一次邮件:

I have made a WordPress cron job that should send out a mail each hour:

function mail_cron_job() {
     $time = date( 'h:ia', time() );
       wp_mail( '****@******', 'Hourly E-mail from WP Cron', 'This message was sent on ' . $time );

}

我在表单提交中添加了以下代码:

I added this code on a form submission:

if ( !wp_next_scheduled('mail_cron_job') ) {
                wp_schedule_event( time(), 'hourly', 'mail_cron_job');
        }

表单数据提交正常,但cron作业无法启动。没有错误报告。我缺少什么?

The form data is submitting OK, but the cron job won't start. No error reports. Anything I'm missing?

推荐答案

您需要使用操作挂钩将事件和功能绑定在一起。

you need to use an action hook to tie the event and function together.

add_action( 'mail_cron_job', 'mail_cron_job' );

您可以在函数后立即添加。

You can add that right after the function.

这篇关于WordPress中的Cron工作无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆