AfterMigrationNotice.php
2 years ago
BlackFridayNotice.php
2 months ago
ChangedTrackingNotice.php
3 years ago
DatabaseEngineNotice.php
1 year ago
DeprecatedFilterNotice.php
4 years ago
DisabledMailFunctionNotice.php
2 months ago
DisabledWPCronNotice.php
1 year ago
EmailWithInvalidSegmentNotice.php
3 years ago
HeadersAlreadySentNotice.php
2 months ago
InactiveSubscribersNotice.php
2 years ago
PHPVersionWarnings.php
2 months ago
PendingApprovalNotice.php
2 years ago
PermanentNotices.php
2 months ago
PremiumFeaturesAvailableNotice.php
2 years ago
SenderDomainAuthenticationNotices.php
5 months ago
SendingQueueBodyCleanupNotice.php
2 months ago
StuckPostNotificationNotice.php
2 months ago
UnauthorizedEmailInNewslettersNotice.php
5 months ago
UnauthorizedEmailNotice.php
5 months ago
WooCommerceVersionWarning.php
1 year ago
WordPressPlaygroundNotice.php
1 year ago
index.php
3 years ago
PremiumFeaturesAvailableNotice.php
80 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Util\Notices; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Config\Installer; |
| 9 | use MailPoet\Config\ServicesChecker; |
| 10 | use MailPoet\Util\Helpers; |
| 11 | use MailPoet\Util\License\Features\Subscribers as SubscribersFeature; |
| 12 | use MailPoet\WP\Functions as WPFunctions; |
| 13 | use MailPoet\WP\Notice; |
| 14 | |
| 15 | class PremiumFeaturesAvailableNotice { |
| 16 | |
| 17 | /** @var SubscribersFeature */ |
| 18 | private $subscribersFeature; |
| 19 | |
| 20 | /** @var ServicesChecker */ |
| 21 | private $servicesChecker; |
| 22 | |
| 23 | /** @var Installer */ |
| 24 | private $premiumInstaller; |
| 25 | |
| 26 | /** @var WPFunctions */ |
| 27 | private $wp; |
| 28 | |
| 29 | const DISMISS_NOTICE_TIMEOUT_SECONDS = 2592000; // 30 days |
| 30 | const OPTION_NAME = 'dismissed-premium-features-available-notice'; |
| 31 | |
| 32 | public function __construct( |
| 33 | SubscribersFeature $subscribersFeature, |
| 34 | ServicesChecker $servicesChecker, |
| 35 | WPFunctions $wp |
| 36 | ) { |
| 37 | $this->subscribersFeature = $subscribersFeature; |
| 38 | $this->servicesChecker = $servicesChecker; |
| 39 | $this->premiumInstaller = new Installer(Installer::PREMIUM_PLUGIN_PATH); |
| 40 | $this->wp = $wp; |
| 41 | } |
| 42 | |
| 43 | public function init($shouldDisplay): ?Notice { |
| 44 | if ( |
| 45 | $shouldDisplay |
| 46 | && !$this->wp->getTransient(self::OPTION_NAME) |
| 47 | && $this->subscribersFeature->hasValidPremiumKey() |
| 48 | && (!Installer::isPluginInstalled(Installer::PREMIUM_PLUGIN_SLUG) || !$this->servicesChecker->isPremiumPluginActive()) |
| 49 | ) { |
| 50 | return $this->display(); |
| 51 | } |
| 52 | |
| 53 | return null; |
| 54 | } |
| 55 | |
| 56 | public function display(): Notice { |
| 57 | $noticeString = __('Your current MailPoet plan includes advanced features, but they require the MailPoet Premium plugin to be installed and activated.', 'mailpoet'); |
| 58 | |
| 59 | // We reuse already existing translations from premium_messages.tsx |
| 60 | if (!Installer::isPluginInstalled(Installer::PREMIUM_PLUGIN_SLUG)) { |
| 61 | $noticeString .= ' [link]' . __('Download MailPoet Premium plugin', 'mailpoet') . '[/link]'; |
| 62 | $link = $this->premiumInstaller->generatePluginDownloadUrl(); |
| 63 | $attributes = ['target' => '_blank']; // Only download link should be opened in a new tab |
| 64 | } else { |
| 65 | $noticeString .= ' [link]' . __('Activate MailPoet Premium plugin', 'mailpoet') . '[/link]'; |
| 66 | $link = $this->premiumInstaller->generatePluginActivationUrl(Installer::PREMIUM_PLUGIN_PATH); |
| 67 | $attributes = []; |
| 68 | } |
| 69 | |
| 70 | $noticeString = Helpers::replaceLinkTags($noticeString, $link, $attributes); |
| 71 | $extraClasses = 'mailpoet-dismissible-notice is-dismissible'; |
| 72 | |
| 73 | return Notice::displaySuccess($noticeString, $extraClasses, self::OPTION_NAME); |
| 74 | } |
| 75 | |
| 76 | public function disable(): void { |
| 77 | WPFunctions::get()->setTransient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS); |
| 78 | } |
| 79 | } |
| 80 |