How to make wp cron job not fire immediately?

I’m scheduling a job in wp cron:

add_action('my_cron_hook', 'my_cron_action');
wp_schedule_event( time(), 'interval1', 'my_cron_hook' ); 

function my_cron_action(){
    //do something
}

The variable interval1 is set by the admin in another part of the code.
Also, there is a switch that lets the admin enable or disable the wp crop job.

Read More

My problem is this:
my_cron_action is executed as soon as it is scheduled
(this means, as soon as the admin enables the cron job from the backend).

What i want to do is this:
if we suppose that the time that the admin enabled the job is T,
i want the job to be run at T+interval1 for the first time, and not at T.

The next thing i want after this is done, is to create a button “Execute job now” that will run the job as soon as it’s clicked.

Related posts

Leave a Reply

1 comment

  1. As described in wp_schedule_event first parameter is $timestamp – the first time that you want the event to occur. So just add interval to $timestamp. I think it should be like

    wp_schedule_event( time() + $delay, 'interval1', 'my_cron_hook' ); 
    

    And set $delay as miliseconds before hook starts.