admin管理员组文章数量:1304239
Ok, let's say I want to give the user the ability to schedule a wp cron event every X minutes. Now, let's say I want X to be anywhere from 10 to 525600 (minutes in a year).
What I'm seeing is an utterly stupid way to handle cron events through the $schedules array. If I understand correctly, I have to add a custom schedule to the array for every single different event time the end user wants. For example:
add_filter( 'cron_schedules', function ( $schedules ) {
$schedules['twelve_minutes'] = array(
'interval' => 12,
'display' => __( 'Twelve Minutes' )
);
return $schedules;
} );
Please tell me there's some way to schedule an event with a custom time without having to add 525,590 unique intervals to the $schedules array.
Ok, let's say I want to give the user the ability to schedule a wp cron event every X minutes. Now, let's say I want X to be anywhere from 10 to 525600 (minutes in a year).
What I'm seeing is an utterly stupid way to handle cron events through the $schedules array. If I understand correctly, I have to add a custom schedule to the array for every single different event time the end user wants. For example:
add_filter( 'cron_schedules', function ( $schedules ) {
$schedules['twelve_minutes'] = array(
'interval' => 12,
'display' => __( 'Twelve Minutes' )
);
return $schedules;
} );
Please tell me there's some way to schedule an event with a custom time without having to add 525,590 unique intervals to the $schedules array.
Share Improve this question asked Feb 24, 2021 at 18:10 uPromptuPrompt 1729 bronze badges 4 |1 Answer
Reset to default 1I use the following code to run a task. this doesn't require adding a cron schedule.
function setup_my_action() {
if (!wp_next_scheduled('my_action')) {
wp_schedule_single_event(time()+3600, 'my_action');
}
}
function my_action() {
// do something
}
add_action('init','setup_my_action');
add_action('my_action', 'my_action');
本文标签: plugin developmentwpscheduleevent custom event time
版权声明:本文标题:plugin development - wp_schedule_event custom event time 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741724735a2394565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_schedule_event
function. – Howdy_McGee ♦ Commented Feb 24, 2021 at 19:17