No Description

PermanentNotices.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace MailPoet\Util\Notices;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\Config\Menu;
  5. use MailPoet\Settings\SettingsController;
  6. use MailPoet\WP\Functions as WPFunctions;
  7. class PermanentNotices {
  8. /** @var WPFunctions */
  9. private $wp;
  10. /** @var PHPVersionWarnings */
  11. private $phpVersionWarnings;
  12. /** @var AfterMigrationNotice */
  13. private $afterMigrationNotice;
  14. /** @var UnauthorizedEmailNotice */
  15. private $unauthorizedEmailsNotice;
  16. /** @var UnauthorizedEmailInNewslettersNotice */
  17. private $unauthorizedEmailsInNewslettersNotice;
  18. /** @var InactiveSubscribersNotice */
  19. private $inactiveSubscribersNotice;
  20. /** @var BlackFridayNotice */
  21. private $blackFridayNotice;
  22. /** @var HeadersAlreadySentNotice */
  23. private $headersAlreadySentNotice;
  24. /** @var DeprecatedShortcodeNotice */
  25. private $deprecatedShortcodeNotice;
  26. /** @var EmailWithInvalidSegmentNotice */
  27. private $emailWithInvalidListNotice;
  28. public function __construct(
  29. WPFunctions $wp
  30. ) {
  31. $this->wp = $wp;
  32. $this->phpVersionWarnings = new PHPVersionWarnings();
  33. $this->afterMigrationNotice = new AfterMigrationNotice();
  34. $this->unauthorizedEmailsNotice = new UnauthorizedEmailNotice(SettingsController::getInstance(), $wp);
  35. $this->unauthorizedEmailsInNewslettersNotice = new UnauthorizedEmailInNewslettersNotice(SettingsController::getInstance(), $wp);
  36. $this->inactiveSubscribersNotice = new InactiveSubscribersNotice(SettingsController::getInstance(), $wp);
  37. $this->blackFridayNotice = new BlackFridayNotice();
  38. $this->headersAlreadySentNotice = new HeadersAlreadySentNotice(SettingsController::getInstance(), $wp);
  39. $this->deprecatedShortcodeNotice = new DeprecatedShortcodeNotice($wp);
  40. $this->emailWithInvalidListNotice = new EmailWithInvalidSegmentNotice($wp);
  41. }
  42. public function init() {
  43. $excludeWizard = [
  44. 'mailpoet-welcome-wizard',
  45. 'mailpoet-woocommerce-setup',
  46. ];
  47. $this->wp->addAction('wp_ajax_dismissed_notice_handler', [
  48. $this,
  49. 'ajaxDismissNoticeHandler',
  50. ]);
  51. $this->phpVersionWarnings->init(
  52. phpversion(),
  53. Menu::isOnMailPoetAdminPage($excludeWizard)
  54. );
  55. $this->afterMigrationNotice->init(
  56. Menu::isOnMailPoetAdminPage($excludeWizard)
  57. );
  58. $this->unauthorizedEmailsNotice->init(
  59. Menu::isOnMailPoetAdminPage($excludeWizard)
  60. );
  61. $this->unauthorizedEmailsInNewslettersNotice->init(
  62. Menu::isOnMailPoetAdminPage($exclude = null, $pageId = 'mailpoet-newsletters')
  63. );
  64. $this->inactiveSubscribersNotice->init(
  65. Menu::isOnMailPoetAdminPage($excludeWizard)
  66. );
  67. $this->blackFridayNotice->init(
  68. Menu::isOnMailPoetAdminPage($excludeWizard)
  69. );
  70. $this->headersAlreadySentNotice->init(
  71. Menu::isOnMailPoetAdminPage($excludeWizard)
  72. );
  73. $this->deprecatedShortcodeNotice->init(
  74. Menu::isOnMailPoetAdminPage($excludeWizard)
  75. );
  76. $this->emailWithInvalidListNotice->init(
  77. Menu::isOnMailPoetAdminPage($exclude = null, $pageId = 'mailpoet-newsletters')
  78. );
  79. }
  80. public function ajaxDismissNoticeHandler() {
  81. if (!isset($_POST['type'])) return;
  82. switch ($_POST['type']) {
  83. case (PHPVersionWarnings::OPTION_NAME):
  84. $this->phpVersionWarnings->disable();
  85. break;
  86. case (AfterMigrationNotice::OPTION_NAME):
  87. $this->afterMigrationNotice->disable();
  88. break;
  89. case (BlackFridayNotice::OPTION_NAME):
  90. $this->blackFridayNotice->disable();
  91. break;
  92. case (HeadersAlreadySentNotice::OPTION_NAME):
  93. $this->headersAlreadySentNotice->disable();
  94. break;
  95. case (InactiveSubscribersNotice::OPTION_NAME):
  96. $this->inactiveSubscribersNotice->disable();
  97. break;
  98. case (DeprecatedShortcodeNotice::OPTION_NAME):
  99. $this->deprecatedShortcodeNotice->disable();
  100. break;
  101. case (EmailWithInvalidSegmentNotice::OPTION_NAME):
  102. $this->emailWithInvalidListNotice->disable();
  103. break;
  104. }
  105. }
  106. }