Brak opisu

UnauthorizedEmailNotice.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace MailPoet\Util\Notices;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\Newsletter\Renderer\EscapeHelper;
  5. use MailPoet\Services\AuthorizedEmailsController;
  6. use MailPoet\Settings\SettingsController;
  7. use MailPoet\WP\Functions as WPFunctions;
  8. use MailPoet\WP\Notice;
  9. class UnauthorizedEmailNotice {
  10. const OPTION_NAME = 'unauthorized-email-addresses-notice';
  11. /** @var SettingsController */
  12. private $settings;
  13. /** @var WPFunctions */
  14. private $wp;
  15. public function __construct(
  16. SettingsController $settings,
  17. WPFunctions $wp
  18. ) {
  19. $this->settings = $settings;
  20. $this->wp = $wp;
  21. }
  22. public function init($shouldDisplay) {
  23. $validationError = $this->settings->get(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING);
  24. if ($shouldDisplay && isset($validationError['invalid_sender_address'])) {
  25. return $this->display($validationError);
  26. }
  27. }
  28. public function display($validationError) {
  29. $message = $this->getMessageText($validationError);
  30. $message .= $this->getFixThisButton();
  31. $extraClasses = 'mailpoet-js-error-unauthorized-emails-notice';
  32. Notice::displayError($message, $extraClasses, self::OPTION_NAME, false, false);
  33. }
  34. private function getMessageText($validationError) {
  35. $text = $this->wp->_x('<b>Sending all of your emails has been paused</b> because your email address %s hasn’t been authorized yet.',
  36. 'Email addresses have to be authorized to be used to send emails. %s will be replaced by an email address.',
  37. 'mailpoet');
  38. $message = str_replace('%s', EscapeHelper::escapeHtmlText($validationError['invalid_sender_address']), $text);
  39. return "<p>$message</p>";
  40. }
  41. private function getFixThisButton() {
  42. $button = '<button class="button button-primary mailpoet-js-button-fix-this">' . $this->wp->__('Fix this!', 'mailpoet') . '</button>';
  43. return "<p>$button</p>";
  44. }
  45. }