PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.2.0
JetBackup – Backup, Restore & Migrate v1.2.0
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / com / core / schedule / SGScheduleAdapterWordpress.php
backup / com / core / schedule Last commit date
SGIScheduleAdapter.php 6 years ago SGSchedule.php 6 years ago SGScheduleAdapterWordpress.php 6 years ago
SGScheduleAdapterWordpress.php
125 lines
1 <?php
2 require_once(SG_SCHEDULE_PATH.'SGIScheduleAdapter.php');
3
4 class SGScheduleAdapterWordpress implements SGIScheduleAdapter
5 {
6 public static function create($cron, $id = SG_SCHEDULER_DEFAULT_ID)
7 {
8 if (!self::isCronAvailable()) {
9 return false;
10 }
11
12 $cronExecutionData = self::getCronExecutionData($cron);
13 $time = $cronExecutionData['time'];
14 $recurrence = $cronExecutionData['recurrence'];
15
16 $args = array((int)$id);
17
18 $dateString = backupGuardConvertDateTimezone(@date("Y-m-d H:i:s", $time));
19 $time = strtotime($dateString);
20 $res = wp_schedule_event($time, $recurrence, SG_SCHEDULE_ACTION, $args);
21 }
22
23 public static function getCronExecutionData($cron)
24 {
25 $recurrence = '';
26 $tmpTime = self::getTmpTime($cron['intervalHour']);
27
28 if ($cron['interval'] == BG_SCHEDULE_INTERVAL_HOURLY) {
29 $recurrence = 'hourly';
30 $time = time() + 3600;
31 }
32 else if ($cron['interval'] == BG_SCHEDULE_INTERVAL_DAILY) {
33 $recurrence = 'daily';
34
35 if ($tmpTime < time()) {
36 $time = strtotime('Next day '.sprintf("%02d:00", $cron['intervalHour']));
37 }
38 else {
39 $time = $tmpTime;
40 }
41 }
42 else if ($cron['interval'] == BG_SCHEDULE_INTERVAL_WEEKLY) {
43 $recurrence = 'weekly';
44 $dayOfInterval = $cron['dayOfInterval'];
45
46 switch ($dayOfInterval) {
47 case 1:
48 $dayOfInterval = 'Monday';
49 break;
50 case 2:
51 $dayOfInterval = 'Tuesday';
52 break;
53 case 3:
54 $dayOfInterval = 'Wednesday';
55 break;
56 case 4:
57 $dayOfInterval = 'Thursday';
58 break;
59 case 5:
60 $dayOfInterval = 'Friday';
61 break;
62 case 6:
63 $dayOfInterval = 'Saturday';
64 break;
65 case 7:
66 $dayOfInterval = 'Sunday';
67 break;
68 default:
69 $dayOfInterval = 'Monday';
70 break;
71 }
72
73 if ($tmpTime < time()) {
74 $time = strtotime('Next '.$dayOfInterval.' '.sprintf("%02d:00", $cron['intervalHour']));
75 }
76 else {
77 $time = strtotime('this '.$dayOfInterval.' '.sprintf("%02d:00", $cron['intervalHour']));
78 }
79 }
80 else if ($cron['interval'] == BG_SCHEDULE_INTERVAL_MONTHLY) {
81 $recurrence = 'monthly';
82 $dayOfInterval = $cron['dayOfInterval'];
83 $today = (int)date('d');
84
85 if ($today < $dayOfInterval) {
86 $time = $tmpTime + ($dayOfInterval - $today) * SG_ONE_DAY_IN_SECONDS;
87 }
88 else {
89 if ($tmpTime > time() && $today == $dayOfInterval) {
90 $time = $tmpTime;
91 }
92 else {
93 $time = strtotime('first day of next month '.sprintf("%02d:00", $cron['intervalHour']));
94 $time += ($dayOfInterval - 1) * SG_ONE_DAY_IN_SECONDS;
95 }
96 }
97 }
98 else {
99 $recurrence = 'yearly';
100 $time = strtotime('Next year today '.sprintf("%02d:00", $cron['intervalHour']));
101 }
102
103 return array(
104 'time' => $time,
105 'recurrence' => $recurrence
106 );
107 }
108
109 public static function remove($id = SG_SCHEDULER_DEFAULT_ID)
110 {
111 $args = array((int)$id);
112 wp_clear_scheduled_hook(SG_SCHEDULE_ACTION, $args);
113 }
114
115 public static function getTmpTime($hours)
116 {
117 return strtotime('Today '.sprintf("%02d:00", $hours));
118 }
119
120 public static function isCronAvailable()
121 {
122 return defined('DISABLE_WP_CRON')?DISABLE_WP_CRON:true;
123 }
124 }
125