PluginProbe
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.12.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.12.0
4.12.0 4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 All 67 releases
wp-staging / Backup / Service / UpdateProtectionSettings.php

UpdateProtectionSettings.php in WP STAGING – WordPress Backups, Restore, Migration & Clone 4.12.0, at Backup/Service/UpdateProtectionSettings.php

106 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPStaging\Backup\Service;
4
5 use WPStaging\Core\DTO\Settings;
6 use WPStaging\Core\WPStaging;
7
8
9
10
11
12
13
14 class UpdateProtectionSettings
15 {
16
17 const INTRO_SURFACES = ['modal', 'notice'];
18
19
20
21
22 public function isEnabled(): bool
23 {
24 return WPStaging::make(Settings::class)->isBackupBeforeUpdateEnabled();
25 }
26
27
28
29
30 public function getMode(): string
31 {
32 $mode = (string)get_option(Settings::OPTION_BACKUP_BEFORE_UPDATE_MODE, '');
33
34 return $mode === '' ? 'ask' : $mode;
35 }
36
37
38
39
40
41
42
43 public function forgetMode()
44 {
45 delete_option(Settings::OPTION_BACKUP_BEFORE_UPDATE_MODE);
46 }
47
48
49
50
51
52
53
54
55 public function setEnabled(bool $isEnabled)
56 {
57 $settings = get_option('wpstg_settings', []);
58 if (is_object($settings)) {
59 $settings = (array)$settings;
60 }
61
62 if (!is_array($settings)) {
63 $settings = [];
64 }
65
66 $settings['enableBackupBeforeUpdate'] = $isEnabled ? '1' : '0';
67 update_option('wpstg_settings', $settings);
68
69 if (!$isEnabled) {
70 $this->forgetMode();
71 }
72 }
73
74
75
76
77 public function getIntrosSeen(): array
78 {
79 return array_values(array_filter(explode(',', (string)get_option(Settings::OPTION_BACKUP_BEFORE_UPDATE_INTRO_SEEN, ''))));
80 }
81
82
83
84
85
86 public function hasSeenIntro(string $surface): bool
87 {
88 return in_array($surface, $this->getIntrosSeen(), true);
89 }
90
91
92
93
94
95 public function markIntroSeen(string $surface)
96 {
97 $seen = $this->getIntrosSeen();
98 if (in_array($surface, $seen, true)) {
99 return;
100 }
101
102 $seen[] = $surface;
103 update_option(Settings::OPTION_BACKUP_BEFORE_UPDATE_INTRO_SEEN, implode(',', $seen));
104 }
105 }
106