我正在制作一个程序,用wp_schedule_event在一个小时内检查和发送电子邮件,但它不会在我的终端上工作。有人知道我的案子吗?这是我的代码,我把它放在我的自定义插件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');
}发布于 2015-08-21 08:50:20
由于您的代码似乎是从WP文档中删除的,我认为与其说是代码的问题,不如说是配置问题。
也许这些步骤可以帮助你:
WP_DEBUG文件中的wp-config.php是否设置为trueDISABLE_WP_CRON是否存在,或者至少在wp-config.php文件中没有设置为true$schedule = wp_get_schedule( 'my_hourly_event' );,然后转储schedule。wp_cron.php文件的错误。我知道我没有给你任何答复,但我们没有太多的信息(正如你没有)。
希望它能帮到你。
https://stackoverflow.com/questions/32132835
复制相似问题