diff --git a/mailpoet/lib/Util/Notices/PermanentNotices.php b/mailpoet/lib/Util/Notices/PermanentNotices.php index d37a6872d5..1f991783e3 100644 --- a/mailpoet/lib/Util/Notices/PermanentNotices.php +++ b/mailpoet/lib/Util/Notices/PermanentNotices.php @@ -3,6 +3,7 @@ namespace MailPoet\Util\Notices; use MailPoet\Config\Menu; +use MailPoet\Config\ServicesChecker; use MailPoet\Mailer\MailerFactory; use MailPoet\Settings\SettingsController; use MailPoet\Settings\TrackingConfig; @@ -54,12 +55,16 @@ class PermanentNotices { /** @var WooCommerceVersionWarning */ private $woocommerceVersionWarning; + /** @var PremiumFeaturesAvailableNotice */ + private $premiumFeaturesAvailableNotice; + public function __construct( WPFunctions $wp, TrackingConfig $trackingConfig, SubscribersRepository $subscribersRepository, SettingsController $settings, SubscribersFeature $subscribersFeature, + ServicesChecker $serviceChecker, MailerFactory $mailerFactory ) { $this->wp = $wp; @@ -76,6 +81,7 @@ class PermanentNotices { $this->disabledMailFunctionNotice = new DisabledMailFunctionNotice($wp, $settings, $subscribersFeature, $mailerFactory); $this->pendingApprovalNotice = new PendingApprovalNotice($settings); $this->woocommerceVersionWarning = new WooCommerceVersionWarning($wp); + $this->premiumFeaturesAvailableNotice = new PremiumFeaturesAvailableNotice($subscribersFeature, $serviceChecker, $wp); } public function init() { @@ -129,6 +135,9 @@ class PermanentNotices { $this->woocommerceVersionWarning->init( Menu::isOnMailPoetAdminPage($excludeSetupWizard) ); + $this->premiumFeaturesAvailableNotice->init( + Menu::isOnMailPoetAdminPage($excludeSetupWizard) + ); } public function ajaxDismissNoticeHandler() { @@ -161,6 +170,9 @@ class PermanentNotices { case (WooCommerceVersionWarning::OPTION_NAME): $this->woocommerceVersionWarning->disable(); break; + case (PremiumFeaturesAvailableNotice::OPTION_NAME): + $this->premiumFeaturesAvailableNotice->disable(); + break; } } } diff --git a/mailpoet/lib/Util/Notices/PremiumFeaturesAvailableNotice.php b/mailpoet/lib/Util/Notices/PremiumFeaturesAvailableNotice.php new file mode 100644 index 0000000000..07c5e5fb18 --- /dev/null +++ b/mailpoet/lib/Util/Notices/PremiumFeaturesAvailableNotice.php @@ -0,0 +1,76 @@ +subscribersFeature = $subscribersFeature; + $this->servicesChecker = $servicesChecker; + $this->premiumInstaller = new Installer(Installer::PREMIUM_PLUGIN_PATH); + $this->wp = $wp; + } + + public function init($shouldDisplay): ?Notice { + if ( + $shouldDisplay + && !$this->wp->getTransient(self::OPTION_NAME) + && $this->subscribersFeature->hasValidPremiumKey() + && (!Installer::isPluginInstalled(Installer::PREMIUM_PLUGIN_SLUG) || !$this->servicesChecker->isPremiumPluginActive()) + ) { + return $this->display(); + } + + return null; + } + + public function display(): Notice { + $noticeString = __('Your current MailPoet plan includes advanced features, but they require the MailPoet Premium plugin to be installed and activated.', 'mailpoet'); + + // We reuse already existing translations from premium_messages.tsx + if (!Installer::isPluginInstalled(Installer::PREMIUM_PLUGIN_SLUG)) { + $noticeString .= ' [link]' . __('Download MailPoet Premium plugin', 'mailpoet') . '[/link]'; + $link = $this->premiumInstaller->generatePluginDownloadUrl(); + $attributes = ['target' => '_blank']; // Only download link should be opened in a new tab + } else { + $noticeString .= ' [link]' . __('Activate MailPoet Premium plugin', 'mailpoet') . '[/link]'; + $link = $this->premiumInstaller->generatePluginActivationUrl(Installer::PREMIUM_PLUGIN_PATH); + $attributes = []; + } + + $noticeString = Helpers::replaceLinkTags($noticeString, $link, $attributes); + $extraClasses = 'mailpoet-dismissible-notice is-dismissible'; + + return Notice::displayInfo($noticeString, $extraClasses, self::OPTION_NAME); + } + + public function disable(): void { + WPFunctions::get()->setTransient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS); + } +}