<?php
namespace MailPoet\Util\Notices;
if (!defined('ABSPATH')) exit;
use MailPoet\Config\Menu;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions;
class PermanentNotices {
/** @var WPFunctions */
private $wp;
/** @var PHPVersionWarnings */
private $phpVersionWarnings;
/** @var AfterMigrationNotice */
private $afterMigrationNotice;
/** @var UnauthorizedEmailNotice */
private $unauthorizedEmailsNotice;
/** @var UnauthorizedEmailInNewslettersNotice */
private $unauthorizedEmailsInNewslettersNotice;
/** @var InactiveSubscribersNotice */
private $inactiveSubscribersNotice;
/** @var BlackFridayNotice */
private $blackFridayNotice;
/** @var HeadersAlreadySentNotice */
private $headersAlreadySentNotice;
/** @var DeprecatedShortcodeNotice */
private $deprecatedShortcodeNotice;
/** @var EmailWithInvalidSegmentNotice */
private $emailWithInvalidListNotice;
public function __construct(
WPFunctions $wp
) {
$this->wp = $wp;
$this->phpVersionWarnings = new PHPVersionWarnings();
$this->afterMigrationNotice = new AfterMigrationNotice();
$this->unauthorizedEmailsNotice = new UnauthorizedEmailNotice(SettingsController::getInstance(), $wp);
$this->unauthorizedEmailsInNewslettersNotice = new UnauthorizedEmailInNewslettersNotice(SettingsController::getInstance(), $wp);
$this->inactiveSubscribersNotice = new InactiveSubscribersNotice(SettingsController::getInstance(), $wp);
$this->blackFridayNotice = new BlackFridayNotice();
$this->headersAlreadySentNotice = new HeadersAlreadySentNotice(SettingsController::getInstance(), $wp);
$this->deprecatedShortcodeNotice = new DeprecatedShortcodeNotice($wp);
$this->emailWithInvalidListNotice = new EmailWithInvalidSegmentNotice($wp);
}
public function init() {
$excludeWizard = [
'mailpoet-welcome-wizard',
'mailpoet-woocommerce-setup',
];
$this->wp->addAction('wp_ajax_dismissed_notice_handler', [
$this,
'ajaxDismissNoticeHandler',
]);
$this->phpVersionWarnings->init(
phpversion(),
Menu::isOnMailPoetAdminPage($excludeWizard)
);
$this->afterMigrationNotice->init(
Menu::isOnMailPoetAdminPage($excludeWizard)
);
$this->unauthorizedEmailsNotice->init(
Menu::isOnMailPoetAdminPage($excludeWizard)
);
$this->unauthorizedEmailsInNewslettersNotice->init(
Menu::isOnMailPoetAdminPage($exclude = null, $pageId = 'mailpoet-newsletters')
);
$this->inactiveSubscribersNotice->init(
Menu::isOnMailPoetAdminPage($excludeWizard)
);
$this->blackFridayNotice->init(
Menu::isOnMailPoetAdminPage($excludeWizard)
);
$this->headersAlreadySentNotice->init(
Menu::isOnMailPoetAdminPage($excludeWizard)
);
$this->deprecatedShortcodeNotice->init(
Menu::isOnMailPoetAdminPage($excludeWizard)
);
$this->emailWithInvalidListNotice->init(
Menu::isOnMailPoetAdminPage($exclude = null, $pageId = 'mailpoet-newsletters')
);
}
public function ajaxDismissNoticeHandler() {
if (!isset($_POST['type'])) return;
switch ($_POST['type']) {
case (PHPVersionWarnings::OPTION_NAME):
$this->phpVersionWarnings->disable();
break;
case (AfterMigrationNotice::OPTION_NAME):
$this->afterMigrationNotice->disable();
break;
case (BlackFridayNotice::OPTION_NAME):
$this->blackFridayNotice->disable();
break;
case (HeadersAlreadySentNotice::OPTION_NAME):
$this->headersAlreadySentNotice->disable();
break;
case (InactiveSubscribersNotice::OPTION_NAME):
$this->inactiveSubscribersNotice->disable();
break;
case (DeprecatedShortcodeNotice::OPTION_NAME):
$this->deprecatedShortcodeNotice->disable();
break;
case (EmailWithInvalidSegmentNotice::OPTION_NAME):
$this->emailWithInvalidListNotice->disable();
break;
}
}
}