BackupPluginsNotice.php
4 days ago
BooleanNotice.php
2 years ago
CliIntegrationNotice.php
4 days ago
DisabledItemsNotice.php
2 years ago
DismissNotice.php
1 month ago
NextGenEngineNotice.php
1 month ago
Notices.php
1 month ago
NoticesHandler.php
4 days ago
ObjectCacheNotice.php
1 year ago
OutdatedWpStagingNotice.php
1 year ago
WarningsNotice.php
2 years ago
WpVersionCompatNotice.php
5 months 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 | * @var string |
| 15 | */ |
| 16 | const OPTION_BACKUP_NOTICE_IS_CLOSED = 'wpstg_backup_notice_is_closed'; |
| 17 | |
| 18 | /** |
| 19 | * @var string |
| 20 | */ |
| 21 | const OPTION_BACKUP_NOTICE_REMINDER = 'wpstg_backup_notice_remind_me'; |
| 22 | |
| 23 | /** |
| 24 | * @var string |
| 25 | */ |
| 26 | const FILTER_HIDE_BACKUP_NOTICE = 'wpstg.notice.hide_backup_notice'; |
| 27 | |
| 28 | /** |
| 29 | * @var Notices |
| 30 | */ |
| 31 | private $notices; |
| 32 | |
| 33 | /** |
| 34 | * @var Auth |
| 35 | */ |
| 36 | private $auth; |
| 37 | |
| 38 | /** |
| 39 | * @var BackupPluginsDetector |
| 40 | */ |
| 41 | private $detector; |
| 42 | |
| 43 | /** |
| 44 | * @var FreeOnboarding |
| 45 | */ |
| 46 | private $onboarding; |
| 47 | |
| 48 | /** |
| 49 | * @param Auth $auth |
| 50 | * @param Notices $notices |
| 51 | * @param BackupPluginsDetector $detector |
| 52 | * @param FreeOnboarding $onboarding |
| 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 | * @return void |
| 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 | // The task selector carries the competitor message inside the backup card instead. |
| 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 | * @return void |
| 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 | * @return void |
| 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 |