BackupPluginsNotice.php
2 years ago
BooleanNotice.php
2 years ago
DisabledItemsNotice.php
2 years ago
DismissNotice.php
2 years ago
FreeBackupUpdateNotice.php
2 years ago
Notices.php
2 years ago
NoticesHandler.php
2 years ago
ObjectCacheNotice.php
2 years ago
OutdatedWpStagingNotice.php
3 years ago
WarningsNotice.php
2 years ago
DismissNotice.php
86 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Notices; |
| 4 | |
| 5 | use WPStaging\Core\WPStaging; |
| 6 | use WPStaging\Framework\ThirdParty\WordFence; |
| 7 | use WPStaging\Pro\Notices\DismissNotice as DismissProNotice; |
| 8 | |
| 9 | /** |
| 10 | * Dismiss notice depending upon post request |
| 11 | */ |
| 12 | class DismissNotice |
| 13 | { |
| 14 | /** |
| 15 | * @var DisabledItemsNotice |
| 16 | */ |
| 17 | private $disabledItemsNotice; |
| 18 | |
| 19 | /** |
| 20 | * @var WarningsNotice |
| 21 | */ |
| 22 | private $warningsNotice; |
| 23 | |
| 24 | /** |
| 25 | * @var WordFence |
| 26 | */ |
| 27 | private $wordFence; |
| 28 | |
| 29 | /** |
| 30 | * @var ObjectCacheNotice |
| 31 | */ |
| 32 | private $objectCacheNotice; |
| 33 | |
| 34 | /** |
| 35 | * @var FreeBackupUpdateNotice |
| 36 | */ |
| 37 | private $freeBackupUpdateNotice; |
| 38 | |
| 39 | public function __construct(DisabledItemsNotice $disabledItemsNotice, WarningsNotice $warningsNotice, WordFence $wordFence, ObjectCacheNotice $objectCacheNotice, FreeBackupUpdateNotice $freeBackupUpdateNotice) |
| 40 | { |
| 41 | $this->disabledItemsNotice = $disabledItemsNotice; |
| 42 | $this->warningsNotice = $warningsNotice; |
| 43 | $this->wordFence = $wordFence; |
| 44 | $this->objectCacheNotice = $objectCacheNotice; |
| 45 | $this->freeBackupUpdateNotice = $freeBackupUpdateNotice; |
| 46 | } |
| 47 | |
| 48 | public function dismiss($noticeToDismiss) |
| 49 | { |
| 50 | if ($noticeToDismiss === 'disabled_items' && $this->disabledItemsNotice->disable() !== false) { |
| 51 | wp_send_json(true); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if ($noticeToDismiss === 'warnings_notice' && $this->warningsNotice->disable() !== false) { |
| 56 | wp_send_json(true); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | // Dismiss wordfence user.ini renamed notice |
| 61 | if ($noticeToDismiss === WordFence::NOTICE_NAME && $this->wordFence->disable() !== false) { |
| 62 | wp_send_json(true); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | if ($noticeToDismiss === ObjectCacheNotice::NOTICE_DISMISS_ACTION && $this->objectCacheNotice->disable() !== false) { |
| 67 | wp_send_json(true); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if ($noticeToDismiss === FreeBackupUpdateNotice::OPTION_NAME_FREE_BACKUP_NOTICE_DISMISSED && $this->freeBackupUpdateNotice->disable() !== false) { |
| 72 | wp_send_json(true); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | if (!WPStaging::isPro()) { |
| 77 | wp_send_json(null); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | /** @var DismissProNotice $dismissProNotice */ |
| 82 | $dismissProNotice = WPStaging::make(DismissProNotice::class); |
| 83 | $dismissProNotice->dismiss($noticeToDismiss); |
| 84 | } |
| 85 | } |
| 86 |