PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.2
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.2
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 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / AdminMenuBadge.php
wp-staging / Backup Last commit date
Ajax 1 week ago BackgroundProcessing 1 week ago Dto 1 week ago Entity 1 week ago Exceptions 3 days ago FileHeader 1 week ago Interfaces 1 week ago Job 3 days ago Request 1 week ago Service 3 days ago Storage 1 week ago Task 3 days ago Traits 1 week ago Utils 1 week ago AdminMenuBadge.php 3 days ago AfterRestore.php 1 week ago BackupDeleter.php 1 week ago BackupDownload.php 1 week ago BackupFileIndex.php 1 week ago BackupGlitchReason.php 1 week ago BackupHeader.php 1 week ago BackupNextOffer.php 3 days ago BackupRepairer.php 1 week ago BackupRetentionHandler.php 1 week ago BackupScheduler.php 3 days ago BackupServiceProvider.php 1 week ago BackupValidator.php 1 week ago BeforeUpdateRowStatus.php 1 week ago FileHeader.php 1 week ago FileHeaderAttribute.php 1 week ago UpdateProtectionPausedNotice.php 1 week ago WithBackupIdentifier.php 1 week ago
AdminMenuBadge.php
94 lines
1 <?php
2
3 namespace WPStaging\Backup;
4
5
6
7
8
9 class AdminMenuBadge
10 {
11
12 private $backupScheduler;
13
14 public function __construct(BackupScheduler $backupScheduler)
15 {
16 $this->backupScheduler = $backupScheduler;
17 }
18
19
20 public function maybeAddBadge()
21 {
22 if (!$this->canReadBadgeState() || !$this->backupScheduler->shouldShowMenuBadge()) {
23 return;
24 }
25
26 global $menu, $submenu;
27
28 $parentSlug = $this->appendBadgeToMenuItem($menu, ['wpstg_clone', 'wpstg_backup']);
29
30 if ($parentSlug === null || !isset($submenu[$parentSlug])) {
31 return;
32 }
33
34 $this->appendBadgeToMenuItem($submenu[$parentSlug], ['wpstg_backup']);
35 }
36
37
38
39
40
41
42
43 private function canReadBadgeState(): bool
44 {
45 return method_exists($this->backupScheduler, 'shouldShowMenuBadge');
46 }
47
48
49
50
51
52
53 private function appendBadgeToMenuItem(array &$menuItems, array $slugs)
54 {
55 foreach ($menuItems as $key => $item) {
56 if (!isset($item[2])) {
57 continue;
58 }
59
60 if (!in_array($item[2], $slugs, true)) {
61 continue;
62 }
63
64 $menuItems[$key][0] .= $this->getBadgeHtml();
65 return $item[2];
66 }
67
68 return null;
69 }
70
71
72 private function getBadgeHtml(): string
73 {
74 return sprintf(
75 ' <span class="update-plugins count-1"><span class="plugin-count" aria-hidden="true">!</span><span class="screen-reader-text">%s</span></span>',
76 esc_html($this->getBadgeLabel())
77 );
78 }
79
80
81
82
83
84
85 private function getBadgeLabel(): string
86 {
87 if ($this->backupScheduler->getWarningType() === BackupScheduler::CRON_WARNING_TYPE_FAILURE) {
88 return __('Last scheduled backup failed.', 'wp-staging');
89 }
90
91 return __('Scheduled backup is overdue.', 'wp-staging');
92 }
93 }
94