Ajax
1 day ago
BackgroundProcessing
1 day ago
Dto
1 day ago
Entity
1 day ago
Exceptions
1 day ago
FileHeader
1 day ago
Interfaces
1 day ago
Job
1 day ago
Request
1 day ago
Service
1 day ago
Storage
1 day ago
Task
1 day ago
Traits
1 day ago
Utils
1 day ago
AfterRestore.php
1 day ago
BackupDeleter.php
1 day ago
BackupDownload.php
1 day ago
BackupFileIndex.php
1 day ago
BackupGlitchReason.php
1 day ago
BackupHeader.php
1 day ago
BackupNextOffer.php
1 day ago
BackupRepairer.php
1 day ago
BackupRetentionHandler.php
1 day ago
BackupScheduler.php
1 day ago
BackupServiceProvider.php
1 day ago
BackupValidator.php
1 day ago
BeforeUpdateRowStatus.php
1 day ago
FileHeader.php
1 day ago
FileHeaderAttribute.php
1 day ago
UpdateProtectionPausedNotice.php
1 day ago
WithBackupIdentifier.php
1 day ago
BeforeUpdateRowStatus.php
119 lines
| 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 |