admin管理员组文章数量:1122832
I am having multiple problems with my simple testing cron snippet.
First, it is not doing its job, which is updating theme option field.
Second, when checking in the Cron Events plugin dashboard, seems like it is not triggering every 3 minutes, as it should do.
Here is the code:
class RedirectionChecker {
public function __construct() {
add_filter('cron_schedules', [ $this, 'add_every_three_minutes' ]);
add_action('init', [ $this, 'schedule_event' ]);
add_action('redirection_checker_hook', [ $this, 'redirection_checker_func' ]);
}
public function add_every_three_minutes($schedules) {
$schedules['every_three_minutes'] = [
'interval' => 180,
'display' => __('Every 3 Minutes')
];
return $schedules;
}
public function schedule_event() {
if (!wp_next_scheduled('redirection_checker_hook')) {
wp_schedule_event(time(), 'every_three_minutes', 'redirection_checker_hook');
}
}
public function redirection_checker_func() {
update_option('test_option', 'success');
}
}
I am having multiple problems with my simple testing cron snippet.
First, it is not doing its job, which is updating theme option field.
Second, when checking in the Cron Events plugin dashboard, seems like it is not triggering every 3 minutes, as it should do.
Here is the code:
class RedirectionChecker {
public function __construct() {
add_filter('cron_schedules', [ $this, 'add_every_three_minutes' ]);
add_action('init', [ $this, 'schedule_event' ]);
add_action('redirection_checker_hook', [ $this, 'redirection_checker_func' ]);
}
public function add_every_three_minutes($schedules) {
$schedules['every_three_minutes'] = [
'interval' => 180,
'display' => __('Every 3 Minutes')
];
return $schedules;
}
public function schedule_event() {
if (!wp_next_scheduled('redirection_checker_hook')) {
wp_schedule_event(time(), 'every_three_minutes', 'redirection_checker_hook');
}
}
public function redirection_checker_func() {
update_option('test_option', 'success');
}
}
Share
Improve this question
asked Jun 4, 2024 at 9:52
Tahi ReuTahi Reu
3081 silver badge14 bronze badges
1 Answer
Reset to default 0You can add debugging statements to your code to verify if the cron job is being scheduled and executed correctly. like you can use error_log() to log messages to the PHP error log:
public function schedule_event() {
if (!wp_next_scheduled('redirection_checker_hook')) {
error_log('Scheduling redirection_checker_hook');
wp_schedule_event(time(), 'every_three_minutes', 'redirection_checker_hook');
}
}
public function redirection_checker_func() {
error_log('Running redirection_checker_func');
update_option('test_option', 'success');
}
本文标签: Having difficulties with WP cron
版权声明:本文标题:Having difficulties with WP cron 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304861a1932384.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论