问题
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:
Check that
WP_DEBUG
in yourwp-config.php
file is set totrue
Check that
DISABLE_WP_CRON
is not present, or at least not setted astrue
in yourwp-config.php
fileTry to check if your event is scheduled
$schedule = wp_get_schedule( 'my_hourly_event' );
, and you dumpschedule
If you can have access to your server logs, take a look if there is errors about the
wp_cron.php
fileTake 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