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 / BeforeUpdateRowStatus.php
BeforeUpdateRowStatus.php
119 lines 2.2 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;
4
5 use WPStaging\Backup\Service\BeforeUpdateBackupRequest;
6 use WPStaging\Backup\Service\UpdateProtectionSettings;
7 use WPStaging\Framework\Assets\I18n;
8
9
10
11
12
13
14
15
16
17
18
19
20
21 class BeforeUpdateRowStatus
22 {
23
24 const ATTRIBUTE = 'data-wpstg-before-update-status';
25
26
27 private $backupRequest;
28
29
30 private $settings;
31
32
33 private $i18n;
34
35
36
37
38
39
40 public function __construct(BeforeUpdateBackupRequest $backupRequest, UpdateProtectionSettings $settings, I18n $i18n)
41 {
42 $this->backupRequest = $backupRequest;
43 $this->settings = $settings;
44 $this->i18n = $i18n;
45 }
46
47
48
49
50
51 public function registerRowMessages()
52 {
53 if (!$this->settings->isEnabled()) {
54 return;
55 }
56
57 foreach ($this->getPluginsWithUpdates() as $pluginFile) {
58 add_action("in_plugin_update_message-{$pluginFile}", [$this, 'renderAnchor'], 10, 2); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
59 }
60 }
61
62
63
64
65
66
67
68
69
70
71 public function renderAnchor($pluginData = [], $response = null)
72 {
73 $pluginFile = '';
74 if (is_object($response) && isset($response->plugin)) {
75 $pluginFile = (string)$response->plugin;
76 }
77
78 printf(
79 ' <span class="wpstg-before-update-status" %s="%s">%s</span>',
80 esc_attr(self::ATTRIBUTE),
81 esc_attr($pluginFile),
82 $this->getStatusText($pluginFile)
83 );
84 }
85
86
87
88
89
90
91
92
93 private function getStatusText(string $pluginFile): string
94 {
95 $position = array_search($pluginFile, $this->backupRequest->getPendingPluginFiles(), true);
96 if ($pluginFile === '' || $position === false) {
97 return '';
98 }
99
100 $sentences = $this->i18n->getTranslations()['backup_before_update'];
101
102 return $position === 0 ? $sentences['row_backing_up'] : $sentences['row_queued'];
103 }
104
105
106
107
108 private function getPluginsWithUpdates(): array
109 {
110 $updates = get_site_transient('update_plugins');
111
112 if (!is_object($updates) || !isset($updates->response) || !is_array($updates->response)) {
113 return [];
114 }
115
116 return array_keys($updates->response);
117 }
118 }
119