@@ -8,7 +8,7 @@ abstract class WPCronable
8
8
9
9
protected int $ wp_cron_interval = 300 ; // 5 minutes
10
10
11
- protected string $ wp_cron_start = 'now ' ;
11
+ protected string | array $ wp_cron_start = 'now ' ;
12
12
13
13
/**
14
14
* @return int|false
@@ -18,6 +18,36 @@ protected function wpCronNextRun()
18
18
return \wp_next_scheduled ($ this ->wp_cron_name );
19
19
}
20
20
21
+ public function getCronStart (): string
22
+ {
23
+
24
+ $ interval = Helpers::getCronScheduleByTime ($ this ->wp_cron_interval );
25
+
26
+ if (! $ interval ) {
27
+ return '' ;
28
+ }
29
+
30
+ if (\is_string ($ this ->wp_cron_start )) {
31
+ return "{$ this ->wp_cron_start } + {$ interval ['value ' ]} seconds " ;
32
+ }
33
+
34
+ if (\is_array ($ this ->wp_cron_start )) {
35
+ $ times = \array_map (function ($ time ) {
36
+ return \strtotime ($ time );
37
+ }, $ this ->wp_cron_start );
38
+
39
+ $ now = \strtotime ('now ' );
40
+
41
+ foreach ($ times as $ time ) {
42
+ if ($ now < $ time ) {
43
+ return \date ('Y-m-d H:i:s ' , $ time );
44
+ }
45
+ }
46
+ }
47
+
48
+ return '' ;
49
+ }
50
+
21
51
public function scheduleCron (): void
22
52
{
23
53
\add_action ($ this ->wp_cron_name , [$ this , 'run ' ]);
@@ -32,7 +62,7 @@ public function scheduleCron(): void
32
62
return ;
33
63
}
34
64
35
- \wp_schedule_event (\strtotime ("{ $ this ->wp_cron_start } + { $ interval [ ' value ' ]} seconds " ), $ interval ['slug ' ], $ this ->wp_cron_name );
65
+ \wp_schedule_event (\strtotime ($ this ->getCronStart () ), $ interval ['slug ' ], $ this ->wp_cron_name );
36
66
}
37
67
38
68
public function unscheduleCron (): void
0 commit comments