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
BlackFridayNotice.php
73 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Util\Notices; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Config\ServicesChecker; |
| 9 | use MailPoet\Util\License\Features\Subscribers; |
| 10 | use MailPoet\WP\Functions as WPFunctions; |
| 11 | use MailPoet\WP\Notice as WPNotice; |
| 12 | |
| 13 | class BlackFridayNotice { |
| 14 | |
| 15 | const OPTION_NAME = 'dismissed-black-friday-notice'; |
| 16 | const DISMISS_NOTICE_TIMEOUT_SECONDS = 2592000; // 30 days |
| 17 | const DATE_FROM = '2024-11-27 15:00:00 UTC'; |
| 18 | const DATE_TO = '2024-12-03 15:00:00 UTC'; |
| 19 | const PARAM_REF = 'sale-bfcm-2024-plugin'; |
| 20 | const PARAM_UTM_CAMPAIGN = 'sale_bfcm_2024'; |
| 21 | |
| 22 | /** @var ServicesChecker */ |
| 23 | private $servicesChecker; |
| 24 | |
| 25 | /** @var Subscribers */ |
| 26 | private $subscribers; |
| 27 | |
| 28 | public function __construct( |
| 29 | ServicesChecker $servicesChecker, |
| 30 | Subscribers $subscribers |
| 31 | ) { |
| 32 | $this->servicesChecker = $servicesChecker; |
| 33 | $this->subscribers = $subscribers; |
| 34 | } |
| 35 | |
| 36 | public function init($shouldDisplay) { |
| 37 | $shouldDisplay = $shouldDisplay |
| 38 | && !$this->servicesChecker->isBundledSubscription() |
| 39 | && (time() >= strtotime(self::DATE_FROM)) |
| 40 | && (time() <= strtotime(self::DATE_TO)) |
| 41 | && !WPFunctions::get()->getTransient(self::OPTION_NAME); |
| 42 | if ($shouldDisplay) { |
| 43 | $this->display(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | private function display() { |
| 48 | $header = '<h3 class="mailpoet-h3">' . __('Save 40% on all MailPoet annual plans and upgrades', 'mailpoet') . '</h3>'; |
| 49 | $body = '<h5 class="mailpoet-h5">' . __('For a limited time, save 40% when you switch to (or upgrade) an annual plan — no coupon needed. Offer ends at 3 pm UTC, December 3, 2024.', 'mailpoet') . '</h5>'; |
| 50 | $link = "<p><a href='" . $this->getSaleUrl() . "' class='mailpoet-button button-primary' target='_blank'>" |
| 51 | // translators: a button on a sale banner |
| 52 | . __('Pick a plan and save big', 'mailpoet') |
| 53 | . '</a></p>'; |
| 54 | |
| 55 | $extraClasses = 'mailpoet-dismissible-notice is-dismissible'; |
| 56 | |
| 57 | WPNotice::displaySuccess($header . $body . $link, $extraClasses, self::OPTION_NAME, false); |
| 58 | } |
| 59 | |
| 60 | public function disable() { |
| 61 | WPFunctions::get()->setTransient(self::OPTION_NAME, true, self::DISMISS_NOTICE_TIMEOUT_SECONDS); |
| 62 | } |
| 63 | |
| 64 | private function getSaleUrl(): string { |
| 65 | $params = 'ref=' . self::PARAM_REF . '&utm_source=plugin&utm_medium=banner&utm_campaign=' . self::PARAM_UTM_CAMPAIGN; |
| 66 | $partialApiKey = $this->servicesChecker->generatePartialApiKey(); |
| 67 | if ($partialApiKey) { |
| 68 | return 'https://account.mailpoet.com/orders/upgrade/' . $partialApiKey . '?' . $params; |
| 69 | } |
| 70 | return 'https://account.mailpoet.com/?s=' . $this->subscribers->getSubscribersCount() . '&' . $params; |
| 71 | } |
| 72 | } |
| 73 |