Add notice when premium features for key are available
[MAILPOET-5429]
This commit is contained in:
@ -3,6 +3,7 @@
|
|||||||
namespace MailPoet\Util\Notices;
|
namespace MailPoet\Util\Notices;
|
||||||
|
|
||||||
use MailPoet\Config\Menu;
|
use MailPoet\Config\Menu;
|
||||||
|
use MailPoet\Config\ServicesChecker;
|
||||||
use MailPoet\Mailer\MailerFactory;
|
use MailPoet\Mailer\MailerFactory;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
use MailPoet\Settings\TrackingConfig;
|
use MailPoet\Settings\TrackingConfig;
|
||||||
@ -54,12 +55,16 @@ class PermanentNotices {
|
|||||||
/** @var WooCommerceVersionWarning */
|
/** @var WooCommerceVersionWarning */
|
||||||
private $woocommerceVersionWarning;
|
private $woocommerceVersionWarning;
|
||||||
|
|
||||||
|
/** @var PremiumFeaturesAvailableNotice */
|
||||||
|
private $premiumFeaturesAvailableNotice;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
WPFunctions $wp,
|
WPFunctions $wp,
|
||||||
TrackingConfig $trackingConfig,
|
TrackingConfig $trackingConfig,
|
||||||
SubscribersRepository $subscribersRepository,
|
SubscribersRepository $subscribersRepository,
|
||||||
SettingsController $settings,
|
SettingsController $settings,
|
||||||
SubscribersFeature $subscribersFeature,
|
SubscribersFeature $subscribersFeature,
|
||||||
|
ServicesChecker $serviceChecker,
|
||||||
MailerFactory $mailerFactory
|
MailerFactory $mailerFactory
|
||||||
) {
|
) {
|
||||||
$this->wp = $wp;
|
$this->wp = $wp;
|
||||||
@ -76,6 +81,7 @@ class PermanentNotices {
|
|||||||
$this->disabledMailFunctionNotice = new DisabledMailFunctionNotice($wp, $settings, $subscribersFeature, $mailerFactory);
|
$this->disabledMailFunctionNotice = new DisabledMailFunctionNotice($wp, $settings, $subscribersFeature, $mailerFactory);
|
||||||
$this->pendingApprovalNotice = new PendingApprovalNotice($settings);
|
$this->pendingApprovalNotice = new PendingApprovalNotice($settings);
|
||||||
$this->woocommerceVersionWarning = new WooCommerceVersionWarning($wp);
|
$this->woocommerceVersionWarning = new WooCommerceVersionWarning($wp);
|
||||||
|
$this->premiumFeaturesAvailableNotice = new PremiumFeaturesAvailableNotice($subscribersFeature, $serviceChecker, $wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
@ -129,6 +135,9 @@ class PermanentNotices {
|
|||||||
$this->woocommerceVersionWarning->init(
|
$this->woocommerceVersionWarning->init(
|
||||||
Menu::isOnMailPoetAdminPage($excludeSetupWizard)
|
Menu::isOnMailPoetAdminPage($excludeSetupWizard)
|
||||||
);
|
);
|
||||||
|
$this->premiumFeaturesAvailableNotice->init(
|
||||||
|
Menu::isOnMailPoetAdminPage($excludeSetupWizard)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxDismissNoticeHandler() {
|
public function ajaxDismissNoticeHandler() {
|
||||||
@ -161,6 +170,9 @@ class PermanentNotices {
|
|||||||
case (WooCommerceVersionWarning::OPTION_NAME):
|
case (WooCommerceVersionWarning::OPTION_NAME):
|
||||||
$this->woocommerceVersionWarning->disable();
|
$this->woocommerceVersionWarning->disable();
|
||||||
break;
|
break;
|
||||||
|
case (PremiumFeaturesAvailableNotice::OPTION_NAME):
|
||||||
|
$this->premiumFeaturesAvailableNotice->disable();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
76
mailpoet/lib/Util/Notices/PremiumFeaturesAvailableNotice.php
Normal file
76
mailpoet/lib/Util/Notices/PremiumFeaturesAvailableNotice.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\Util\Notices;
|
||||||
|
|
||||||
|
use MailPoet\Config\Installer;
|
||||||
|
use MailPoet\Config\ServicesChecker;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
|
use MailPoet\Util\License\Features\Subscribers as SubscribersFeature;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
use MailPoet\WP\Notice;
|
||||||
|
|
||||||
|
class PremiumFeaturesAvailableNotice {
|
||||||
|
|
||||||
|
/** @var SubscribersFeature */
|
||||||
|
private $subscribersFeature;
|
||||||
|
|
||||||
|
/** @var ServicesChecker */
|
||||||
|
private $servicesChecker;
|
||||||
|
|
||||||
|
/** @var Installer */
|
||||||
|
private $premiumInstaller;
|
||||||
|
|
||||||
|
/** @var WPFunctions */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
|
const DISMISS_NOTICE_TIMEOUT_SECONDS = 2592000; // 30 days
|
||||||
|
const OPTION_NAME = 'dismissed-premium-features-available-notice';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
SubscribersFeature $subscribersFeature,
|
||||||
|
ServicesChecker $servicesChecker,
|
||||||
|
WPFunctions $wp
|
||||||
|
) {
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user