BackupPluginsNotice.php
1 day ago
BooleanNotice.php
1 day ago
CliIntegrationNotice.php
1 day ago
DisabledItemsNotice.php
1 day ago
DismissNotice.php
1 day ago
NextGenEngineNotice.php
1 day ago
Notices.php
1 day ago
NoticesHandler.php
1 day ago
ObjectCacheNotice.php
1 day ago
OutdatedWpStagingNotice.php
1 day ago
WarningsNotice.php
1 day ago
WpVersionCompatNotice.php
1 day ago
BackupPluginsNotice.php
133 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Notices; |
| 4 | |
| 5 | use WPStaging\Core\WPStaging; |
| 6 | use WPStaging\Framework\Onboarding\BackupPluginsDetector; |
| 7 | use WPStaging\Framework\Onboarding\FreeOnboarding; |
| 8 | use WPStaging\Framework\Security\Auth; |
| 9 | use WPStaging\Framework\Facades\Hooks; |
| 10 | |
| 11 | class BackupPluginsNotice |
| 12 | { |
| 13 | |
| 14 | |
| 15 | |
| 16 | const OPTION_BACKUP_NOTICE_IS_CLOSED = 'wpstg_backup_notice_is_closed'; |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | const OPTION_BACKUP_NOTICE_REMINDER = 'wpstg_backup_notice_remind_me'; |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | const FILTER_HIDE_BACKUP_NOTICE = 'wpstg.notice.hide_backup_notice'; |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | private $notices; |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | private $auth; |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | private $detector; |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | private $onboarding; |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | public function __construct(Auth $auth, Notices $notices, BackupPluginsDetector $detector, FreeOnboarding $onboarding) |
| 55 | { |
| 56 | $this->notices = $notices; |
| 57 | $this->auth = $auth; |
| 58 | $this->detector = $detector; |
| 59 | $this->onboarding = $onboarding; |
| 60 | } |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | public function maybeShowBackupNotice() |
| 66 | { |
| 67 | if (!$this->notices->isWPStagingAdminPage()) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if (WPStaging::isPro()) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | if (Hooks::applyFilters(self::FILTER_HIDE_BACKUP_NOTICE, false)) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | if ($this->onboarding->isTaskSelector()) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | if (!$this->detector->hasCompetingPlugin()) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | if (!current_user_can('manage_options') || get_option(self::OPTION_BACKUP_NOTICE_IS_CLOSED)) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | $remindMe = get_option(self::OPTION_BACKUP_NOTICE_REMINDER); |
| 93 | |
| 94 | if (!empty($remindMe) && time() < $remindMe) { |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | $notice = WPSTG_VIEWS_DIR . 'notices/backup-plugins-notice.php'; |
| 99 | |
| 100 | if (!file_exists($notice)) { |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | include $notice; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | public function ajaxBackupPluginNoticeClose() |
| 111 | { |
| 112 | if (!$this->auth->isAuthenticatedRequest('', 'manage_options')) { |
| 113 | wp_send_json_error(); |
| 114 | } |
| 115 | |
| 116 | update_option(self::OPTION_BACKUP_NOTICE_IS_CLOSED, true); |
| 117 | wp_send_json_success(); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | public function ajaxBackupPluginNoticeRemindMe() |
| 124 | { |
| 125 | if (!$this->auth->isAuthenticatedRequest('', 'manage_options')) { |
| 126 | wp_send_json_error(); |
| 127 | } |
| 128 | |
| 129 | update_option(self::OPTION_BACKUP_NOTICE_REMINDER, strtotime('+3 days'), false); |
| 130 | wp_send_json_success(); |
| 131 | } |
| 132 | } |
| 133 |