Нема описа

UnauthorizedEmailInNewslettersNotice.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace MailPoet\Util\Notices;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\Config\Menu;
  5. use MailPoet\Mailer\MailerError;
  6. use MailPoet\Mailer\MailerLog;
  7. use MailPoet\Newsletter\Renderer\EscapeHelper;
  8. use MailPoet\Services\AuthorizedEmailsController;
  9. use MailPoet\Settings\SettingsController;
  10. use MailPoet\Util\Helpers;
  11. use MailPoet\WP\Functions as WPFunctions;
  12. class UnauthorizedEmailInNewslettersNotice {
  13. const OPTION_NAME = 'unauthorized-email-in-newsletters-addresses-notice';
  14. /** @var SettingsController */
  15. private $settings;
  16. /** @var WPFunctions */
  17. private $wp;
  18. public function __construct(
  19. SettingsController $settings,
  20. WPFunctions $wp
  21. ) {
  22. $this->settings = $settings;
  23. $this->wp = $wp;
  24. }
  25. public function init($shouldDisplay) {
  26. $validationError = $this->settings->get(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING);
  27. if ($shouldDisplay && isset($validationError['invalid_senders_in_newsletters'])) {
  28. return $this->display($validationError);
  29. }
  30. }
  31. public function display($validationError) {
  32. $message = $this->getMessageText();
  33. $message .= $this->getNewslettersLinks($validationError);
  34. $message .= $this->getFixThisButton();
  35. // Use Mailer log errors display system to display this notice
  36. $mailerLog = MailerLog::setError(MailerLog::getMailerLog(), MailerError::OPERATION_AUTHORIZATION, $message);
  37. MailerLog::updateMailerLog($mailerLog);
  38. }
  39. private function getMessageText() {
  40. $message = $this->wp->__('<b>Your automatic emails have been paused</b> because some email addresses haven’t been authorized yet.', 'mailpoet');
  41. return "<p>$message</p>";
  42. }
  43. private function getNewslettersLinks($validationError) {
  44. $links = '';
  45. foreach ($validationError['invalid_senders_in_newsletters'] as $error) {
  46. $linkText = $this->wp->_x('Update the from address of %s', '%s will be replaced by a newsletter subject', 'mailpoet');
  47. $linkText = str_replace('%s', EscapeHelper::escapeHtmlText($error['subject']), $linkText);
  48. $linkUrl = $this->wp->adminUrl('admin.php?page=' . Menu::MAIN_PAGE_SLUG . '#/send/' . $error['newsletter_id']);
  49. $link = Helpers::replaceLinkTags("[link]{$linkText}[/link]", $linkUrl, ['target' => '_blank']);
  50. $links .= "<p>$link</p>";
  51. }
  52. return $links;
  53. }
  54. private function getFixThisButton() {
  55. $button = '<button class="button button-primary mailpoet-js-button-fix-this">' . $this->wp->__('Fix this!', 'mailpoet') . '</button>';
  56. return "<p>$button</p>";
  57. }
  58. }