Add inactive subscribers notice
[MAILPOET-2088]
This commit is contained in:
@ -601,6 +601,12 @@ class Subscriber extends Model {
|
|||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function getInactiveSubscribersCount() {
|
||||||
|
return self::where('status', self::STATUS_INACTIVE)
|
||||||
|
->whereNull('deleted_at')
|
||||||
|
->count();
|
||||||
|
}
|
||||||
|
|
||||||
static function bulkTrash($orm) {
|
static function bulkTrash($orm) {
|
||||||
$count = parent::bulkAction($orm, function($subscriber_ids) {
|
$count = parent::bulkAction($orm, function($subscriber_ids) {
|
||||||
Subscriber::rawExecute(join(' ', [
|
Subscriber::rawExecute(join(' ', [
|
||||||
|
55
lib/Util/Notices/InactiveSubscribersNotice.php
Normal file
55
lib/Util/Notices/InactiveSubscribersNotice.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Util\Notices;
|
||||||
|
|
||||||
|
use MailPoet\Models\Subscriber;
|
||||||
|
use MailPoet\Settings\SettingsController;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
use MailPoet\WP\Notice;
|
||||||
|
|
||||||
|
class InactiveSubscribersNotice {
|
||||||
|
const OPTION_NAME = 'inactive-subscribers-notice';
|
||||||
|
const MIN_INACTIVE_SUBSCRIBERS_COUNT = 50;
|
||||||
|
|
||||||
|
/** @var SettingsController */
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
/** @var WPFunctions */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
|
function __construct(SettingsController $settings, WPFunctions $wp) {
|
||||||
|
$this->settings = $settings;
|
||||||
|
$this->wp = $wp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function init($should_display) {
|
||||||
|
if (!$should_display || !$this->settings->get(self::OPTION_NAME, true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$inactive_subscribers_count = Subscriber::getInactiveSubscribersCount();
|
||||||
|
if ($inactive_subscribers_count < self::MIN_INACTIVE_SUBSCRIBERS_COUNT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return $this->display($inactive_subscribers_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
function disable() {
|
||||||
|
$this->settings->set(self::OPTION_NAME, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function display($inactive_subscribers_count) {
|
||||||
|
$error_string = __('Good news! MailPoet won’t send emails to your [number] 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');
|
||||||
|
$go_to_settings_string = __('Go to the Advanced Settings', 'mailpoet');
|
||||||
|
|
||||||
|
$notice = str_replace('[number]', $this->wp->numberFormatI18n($inactive_subscribers_count), $error_string);
|
||||||
|
$notice = Helpers::replaceLinkTags($notice, 'https://kb.mailpoet.com/article/264-inactive-subscribers', ['target' => '_blank']);
|
||||||
|
$notice = "<p>$notice</p>";
|
||||||
|
$notice .= '<p><a href="admin.php?page=mailpoet-settings#advanced" class="button button-primary">' . $go_to_settings_string . '</a></p>';
|
||||||
|
|
||||||
|
$extra_classes = 'mailpoet-dismissible-notice is-dismissible';
|
||||||
|
|
||||||
|
return Notice::displaySuccess($notice, $extra_classes, self::OPTION_NAME, false);
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,9 @@ class PermanentNotices {
|
|||||||
/** @var UnauthorizedEmailInNewslettersNotice */
|
/** @var UnauthorizedEmailInNewslettersNotice */
|
||||||
private $unauthorized_emails_in_newsletters_notice;
|
private $unauthorized_emails_in_newsletters_notice;
|
||||||
|
|
||||||
|
/** @var InactiveSubscribersNotice */
|
||||||
|
private $inactive_subscribers_notice;
|
||||||
|
|
||||||
/** @var WPFunctions */
|
/** @var WPFunctions */
|
||||||
private $wp;
|
private $wp;
|
||||||
|
|
||||||
@ -33,6 +36,7 @@ class PermanentNotices {
|
|||||||
$this->discounts_announcement = new DiscountsAnnouncement();
|
$this->discounts_announcement = new DiscountsAnnouncement();
|
||||||
$this->unauthorized_emails_notice = new UnauthorizedEmailNotice(new SettingsController, $this->wp);
|
$this->unauthorized_emails_notice = new UnauthorizedEmailNotice(new SettingsController, $this->wp);
|
||||||
$this->unauthorized_emails_in_newsletters_notice = new UnauthorizedEmailInNewslettersNotice(new SettingsController, $this->wp);
|
$this->unauthorized_emails_in_newsletters_notice = new UnauthorizedEmailInNewslettersNotice(new SettingsController, $this->wp);
|
||||||
|
$this->inactive_subscribers_notice = new InactiveSubscribersNotice(new SettingsController, $this->wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
@ -54,6 +58,9 @@ class PermanentNotices {
|
|||||||
$this->unauthorized_emails_in_newsletters_notice->init(
|
$this->unauthorized_emails_in_newsletters_notice->init(
|
||||||
Menu::isOnMailPoetAdminPage($exclude = null, $page_id = 'mailpoet-newsletters')
|
Menu::isOnMailPoetAdminPage($exclude = null, $page_id = 'mailpoet-newsletters')
|
||||||
);
|
);
|
||||||
|
$this->inactive_subscribers_notice->init(
|
||||||
|
Menu::isOnMailPoetAdminPage($exclude = ['mailpoet-welcome-wizard'])
|
||||||
|
);
|
||||||
$this->discounts_announcement->init(
|
$this->discounts_announcement->init(
|
||||||
empty($_GET['page'])
|
empty($_GET['page'])
|
||||||
&& $this->wp->isAdmin()
|
&& $this->wp->isAdmin()
|
||||||
@ -73,6 +80,9 @@ class PermanentNotices {
|
|||||||
case (DiscountsAnnouncement::OPTION_NAME):
|
case (DiscountsAnnouncement::OPTION_NAME):
|
||||||
$this->discounts_announcement->disable();
|
$this->discounts_announcement->disable();
|
||||||
break;
|
break;
|
||||||
|
case (InactiveSubscribersNotice::OPTION_NAME):
|
||||||
|
$this->inactive_subscribers_notice->disable();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user