admin管理员组文章数量:1130349
I have some programming error in my wordpress plugin. When its running, then it keeps registering cron job to the wordpress. I wrote the plugin as a class:
class Cleverstart_Woofio extends WC_Integration{
public function __construct(){
add_action('woofio_hourly', array( $this,'woofio_create_haystack'));
wp_schedule_event(time(), 'hourly', 'woofio_hourly');
//other stuff not related to the question
}
public function woofio_create_haystack(){
//do quite performance heavy stuff
}
}
$cleverstart_woofio = new Cleverstart_Woofio();
My theory is, that the new Cleverstart_Woofio(); call will always schedule new cron event, clugging my site. I need to check if the event was already scheduled and schedule it only once. However, I am clueless on how to achieve this.
Thanks for help
I have some programming error in my wordpress plugin. When its running, then it keeps registering cron job to the wordpress. I wrote the plugin as a class:
class Cleverstart_Woofio extends WC_Integration{
public function __construct(){
add_action('woofio_hourly', array( $this,'woofio_create_haystack'));
wp_schedule_event(time(), 'hourly', 'woofio_hourly');
//other stuff not related to the question
}
public function woofio_create_haystack(){
//do quite performance heavy stuff
}
}
$cleverstart_woofio = new Cleverstart_Woofio();
My theory is, that the new Cleverstart_Woofio(); call will always schedule new cron event, clugging my site. I need to check if the event was already scheduled and schedule it only once. However, I am clueless on how to achieve this.
Thanks for help
Share Improve this question asked Jan 7, 2019 at 9:33 Pavel JanicekPavel Janicek 2123 silver badges14 bronze badges1 Answer
Reset to default 5Have you ever heard of Rubber Ducking?
The official documentation has an answer:
if ( ! wp_next_scheduled( 'woofio_hourly' ) ) {
wp_schedule_event( time(), 'hourly', 'woofio_hourly' );
}
I have some programming error in my wordpress plugin. When its running, then it keeps registering cron job to the wordpress. I wrote the plugin as a class:
class Cleverstart_Woofio extends WC_Integration{
public function __construct(){
add_action('woofio_hourly', array( $this,'woofio_create_haystack'));
wp_schedule_event(time(), 'hourly', 'woofio_hourly');
//other stuff not related to the question
}
public function woofio_create_haystack(){
//do quite performance heavy stuff
}
}
$cleverstart_woofio = new Cleverstart_Woofio();
My theory is, that the new Cleverstart_Woofio(); call will always schedule new cron event, clugging my site. I need to check if the event was already scheduled and schedule it only once. However, I am clueless on how to achieve this.
Thanks for help
I have some programming error in my wordpress plugin. When its running, then it keeps registering cron job to the wordpress. I wrote the plugin as a class:
class Cleverstart_Woofio extends WC_Integration{
public function __construct(){
add_action('woofio_hourly', array( $this,'woofio_create_haystack'));
wp_schedule_event(time(), 'hourly', 'woofio_hourly');
//other stuff not related to the question
}
public function woofio_create_haystack(){
//do quite performance heavy stuff
}
}
$cleverstart_woofio = new Cleverstart_Woofio();
My theory is, that the new Cleverstart_Woofio(); call will always schedule new cron event, clugging my site. I need to check if the event was already scheduled and schedule it only once. However, I am clueless on how to achieve this.
Thanks for help
Share Improve this question asked Jan 7, 2019 at 9:33 Pavel JanicekPavel Janicek 2123 silver badges14 bronze badges1 Answer
Reset to default 5Have you ever heard of Rubber Ducking?
The official documentation has an answer:
if ( ! wp_next_scheduled( 'woofio_hourly' ) ) {
wp_schedule_event( time(), 'hourly', 'woofio_hourly' );
}
本文标签: wp cronCheck if event was scheduledschedule event only once
版权声明:本文标题:wp cron - Check if event was scheduled - schedule event only once 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749036285a2306441.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论