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 2 weeks ago Dto 1 week ago Entity 2 weeks ago Exceptions 4 days ago FileHeader 2 weeks ago Interfaces 2 weeks ago Job 4 days ago Request 2 weeks ago Service 4 days ago Storage 2 weeks ago Task 4 days ago Traits 2 weeks ago Utils 2 weeks ago AdminMenuBadge.php 4 days ago AfterRestore.php 2 weeks ago BackupDeleter.php 2 weeks ago BackupDownload.php 2 weeks ago BackupFileIndex.php 2 weeks ago BackupGlitchReason.php 2 weeks ago BackupHeader.php 1 week ago BackupNextOffer.php 4 days ago BackupRepairer.php 2 weeks ago BackupRetentionHandler.php 2 weeks ago BackupScheduler.php 4 days ago BackupServiceProvider.php 2 weeks ago BackupValidator.php 1 week ago BeforeUpdateRowStatus.php 2 weeks ago FileHeader.php 2 weeks ago FileHeaderAttribute.php 2 weeks ago UpdateProtectionPausedNotice.php 2 weeks ago WithBackupIdentifier.php 2 weeks 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