wp_schedule_event 不起作用 [英] wp_schedule_event not working
问题描述
我正在制作一个使用 wp_schedule_event
在一小时内检查和发送电子邮件的程序,但它对我不起作用..有人知道我的情况吗?这是我的代码我把它放在我的自定义插件 myplugin-function.php
I am making a program that checks and send email in an hour using wp_schedule_event
but it won't work on my end.. does any one have an idea about my case? this is my code I put it on my custom plugin myplugin-function.php
register_activation_hook(__FILE__, 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');
function my_activation() {
wp_schedule_event(time(), 'hourly', 'my_hourly_event');
}
function do_this_hourly() {
$headers = "From: webmaster <webmaster@test.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail('mymail@test.com','Test','Hello',$headers);
}
register_deactivation_hook(__FILE__, 'my_deactivation');
function my_deactivation() {
wp_clear_scheduled_hook('my_hourly_event');
}
推荐答案
由于您的代码似乎是从 WP 文档中删除的,我认为这与其说是代码问题,不如说是配置问题.
As your code seems to be taken out of the WP doc, I would think it's more a config issue than a code's problem.
也许这些步骤应该对您有所帮助:
Maybe these steps should help you:
检查
wp-config.php
文件中的WP_DEBUG
是否设置为true
Check that
WP_DEBUG
in yourwp-config.php
file is set totrue
检查 DISABLE_WP_CRON
是否不存在,或者至少没有在您的 wp-config.php
文件中设置为 true
Check that DISABLE_WP_CRON
is not present, or at least not setted as true
in your wp-config.php
file
尝试检查您的活动是否已安排$schedule = wp_get_schedule('my_hourly_event');
,然后您转储schedule
Try to check if your event is scheduled $schedule = wp_get_schedule( 'my_hourly_event' );
, and you dump schedule
如果您可以访问服务器日志,请查看 wp_cron.php
文件是否存在错误
If you can have access to your server logs, take a look if there is errors about the wp_cron.php
file
查看 ALTERNATE_WP_CRON 选项文档,它可能对你有帮助,但我不太喜欢这个解决方案
Take a look at the ALTERNATE_WP_CRON option docs, it may helps you, but I don't really like this solution
我知道我没有给你任何答案,但我们没有很多信息(你也没有).
I know that I don't give you any answer but we don't have a lot of information (as you don't).
希望能帮到你.
这篇关于wp_schedule_event 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!