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
InactiveSubscribersNotice.php
80 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\Entities\SubscriberEntity; |
| 9 | use MailPoet\Settings\SettingsController; |
| 10 | use MailPoet\Subscribers\SubscribersRepository; |
| 11 | use MailPoet\Util\Helpers; |
| 12 | use MailPoet\WP\Functions as WPFunctions; |
| 13 | use MailPoet\WP\Notice; |
| 14 | |
| 15 | class InactiveSubscribersNotice { |
| 16 | const OPTION_NAME = 'inactive-subscribers-notice'; |
| 17 | const MIN_INACTIVE_SUBSCRIBERS_COUNT = 50; |
| 18 | |
| 19 | /** @var SettingsController */ |
| 20 | private $settings; |
| 21 | |
| 22 | /** @var SubscribersRepository */ |
| 23 | private $subscribersRepository; |
| 24 | |
| 25 | /** @var WPFunctions */ |
| 26 | private $wp; |
| 27 | |
| 28 | public function __construct( |
| 29 | SettingsController $settings, |
| 30 | SubscribersRepository $subscribersRepository, |
| 31 | WPFunctions $wp |
| 32 | ) { |
| 33 | $this->settings = $settings; |
| 34 | $this->wp = $wp; |
| 35 | $this->subscribersRepository = $subscribersRepository; |
| 36 | } |
| 37 | |
| 38 | public function init($shouldDisplay) { |
| 39 | if (!$shouldDisplay || !$this->settings->get(self::OPTION_NAME, true)) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | // don't display notice if user has changed the default inactive time range |
| 44 | $inactiveDays = (int)$this->settings->get('deactivate_subscriber_after_inactive_days'); |
| 45 | if ($inactiveDays !== SettingsController::DEFAULT_DEACTIVATE_SUBSCRIBER_AFTER_INACTIVE_DAYS) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | $inactiveSubscribersCount = $this->subscribersRepository->countBy(['deletedAt' => null, 'status' => SubscriberEntity::STATUS_INACTIVE]); |
| 50 | if ($inactiveSubscribersCount < self::MIN_INACTIVE_SUBSCRIBERS_COUNT) { |
| 51 | return; |
| 52 | } |
| 53 | return $this->display($inactiveSubscribersCount); |
| 54 | } |
| 55 | |
| 56 | public function disable() { |
| 57 | $this->settings->set(self::OPTION_NAME, false); |
| 58 | } |
| 59 | |
| 60 | private function display($inactiveSubscribersCount) { |
| 61 | $goToSettingsString = __('Go to the Advanced Settings', 'mailpoet'); |
| 62 | |
| 63 | $notice = sprintf( |
| 64 | // translators: %d is the number of inactive subscribers. |
| 65 | __('Good news! MailPoet won’t send emails to your %s inactive subscribers. This is a standard practice to maintain good deliverability and open rates. But if you want to disable it, you can do so in settings. [link]Read more.[/link]', 'mailpoet'), |
| 66 | $this->wp->numberFormatI18n($inactiveSubscribersCount) |
| 67 | ); |
| 68 | $notice = Helpers::replaceLinkTags($notice, 'https://kb.mailpoet.com/article/264-inactive-subscribers', [ |
| 69 | 'target' => '_blank', |
| 70 | ]); |
| 71 | $notice = "<p>$notice</p>"; |
| 72 | $notice .= '<p><a href="admin.php?page=mailpoet-settings#advanced" class="button button-primary">' . $goToSettingsString . '</a></p>'; |
| 73 | |
| 74 | $extraClasses = 'mailpoet-dismissible-notice is-dismissible'; |
| 75 | |
| 76 | Notice::displaySuccess($notice, $extraClasses, self::OPTION_NAME, false); |
| 77 | return $notice; |
| 78 | } |
| 79 | } |
| 80 |