BasicNotices.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Basic\Notices; |
| 4 | |
| 5 | use Exception; |
| 6 | use WPStaging\Basic\Ajax\ProCronsCleaner; |
| 7 | use WPStaging\Core\WPStaging; |
| 8 | use WPStaging\Framework\Assets\Assets; |
| 9 | use WPStaging\Framework\Notices\FreeBackupUpdateNotice; |
| 10 | use WPStaging\Framework\Notices\Notices; |
| 11 | use WPStaging\Framework\Traits\NoticesTrait; |
| 12 | |
| 13 | class BasicNotices |
| 14 | { |
| 15 | use NoticesTrait; |
| 16 | |
| 17 | /** @var bool */ |
| 18 | private $showAllNotices; |
| 19 | |
| 20 | /** @var RatingNotice */ |
| 21 | private $ratingNotice; |
| 22 | |
| 23 | /** @var ProCronsCleaner */ |
| 24 | private $proCronsCleaner; |
| 25 | |
| 26 | /** @var Assets */ |
| 27 | private $assets; |
| 28 | |
| 29 | /** |
| 30 | * @var FreeBackupUpdateNotice |
| 31 | */ |
| 32 | private $freeBackupUpdateNotice; |
| 33 | |
| 34 | public function __construct(Assets $assets, RatingNotice $ratingNotice, ProCronsCleaner $proCronsCleaner, FreeBackupUpdateNotice $freeBackupUpdateNotice) |
| 35 | { |
| 36 | $this->showAllNotices = Notices::SHOW_ALL_NOTICES; |
| 37 | $this->noticesViewPath = trailingslashit($this->getPluginPath()) . "Backend/views/notices/"; |
| 38 | $this->assets = $assets; |
| 39 | $this->ratingNotice = $ratingNotice; |
| 40 | $this->proCronsCleaner = $proCronsCleaner; |
| 41 | $this->freeBackupUpdateNotice = $freeBackupUpdateNotice; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Load admin notices for FREE version only |
| 46 | * @throws Exception |
| 47 | */ |
| 48 | public function renderNotices() |
| 49 | { |
| 50 | $viewsNoticesPath = $this->noticesViewPath; |
| 51 | |
| 52 | // Only show below notices on WP Staging admin pages |
| 53 | if (!$this->isWPStagingAdminPage()) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | // Show notice "rate the plugin" |
| 58 | // We used to have this message on all pages but added a new nonce based authentication check. |
| 59 | // As the nonce is not loaded on all pages we had to move this message to wp staging pages only. |
| 60 | // @todo add our nonce to all wp staging pages and move this message back to all pages |
| 61 | if ($this->showAllNotices || $this->ratingNotice->shouldShowRatingNotice()) { |
| 62 | require_once "{$viewsNoticesPath}rating.php"; |
| 63 | } |
| 64 | |
| 65 | if ($this->showAllNotices || $this->proCronsCleaner->haveProCrons()) { |
| 66 | require_once "{$viewsNoticesPath}pro-crons-notice.php"; |
| 67 | } |
| 68 | |
| 69 | // Show notice WP STAGING is not tested with current WordPress version |
| 70 | if ($this->showAllNotices || version_compare(WPStaging::getInstance()->get('WPSTG_COMPATIBLE'), get_bloginfo("version"), "<")) { |
| 71 | require_once "{$viewsNoticesPath}wp-version-compatible-message.php"; |
| 72 | } |
| 73 | |
| 74 | if ($this->showAllNotices || $this->freeBackupUpdateNotice->isEnabled()) { |
| 75 | require_once "{$viewsNoticesPath}free-backup-update-notice.php"; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |