wp_schedule_event not working

坚强是说给别人听的谎言 提交于 2019-12-11 16:29:10

问题


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');
}

回答1:


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:

  1. Check that WP_DEBUG in your wp-config.php file is set to true

  2. Check that DISABLE_WP_CRON is not present, or at least not setted as true in your wp-config.php file

  3. Try to check if your event is scheduled $schedule = wp_get_schedule( 'my_hourly_event' );, and you dump schedule

  4. If you can have access to your server logs, take a look if there is errors about the wp_cron.php file

  5. 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).

Hope it's gonna help you.



来源:https://stackoverflow.com/questions/32132835/wp-schedule-event-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!