0

I have created this interval in my functions.php:

function minute_interval( $schedules ) {
  $schedules['minute'] = array(
    'interval' => 60,
    'display' => __('Every minute')
  );
  return $schedules;
}
add_filter( 'cron_schedules', 'minute_interval' );

I have this scheduled event in my plugin:

if (! wp_next_scheduled ( 'my_event' )) {
    wp_schedule_event( time(), 'minute', 'my_event');
}

add_action( 'my_event', 'my_function' );
function my_function() {
    update_option('test_option', 'test_value');
}

The event is added to the scheduled events list. However, it seems not to start my_function() as Wordpress does not create or update "test_option".

Others scheduled events from Wordpress are working well.

Any idea how I could make my event work?

Edit: after installing WP control, here's what is displayed :

enter image description here

edit2: my wp_schedule_event() and my_function() are both in the initialization function of my plugin, which is started when my plugin is activated.

  • to debug that, try a plugin like WP Crontrol to look if your event is realy scheduled. – mmm Jan 6 '18 at 20:13
1

You have to add filter:

add_filter( 'cron_schedules', 'minute_interval' );

Otherwise your function minute_interval is not invoked, interval is not defined, and event doesn't work.

  • Hi, thanks for your reply. I do have this line, I just forgot to copy paste it. – Gaston Flanchard Jan 6 '18 at 23:50
0

I had to move my_function() outside my plugin init function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.