Files
piratepoet/lib/Util/Notices/UnauthorizedEmailNotice.php
Pavel Dohnal cf5e761ba4 Remove duplicite button
[MAILPOET-2888]
2020-05-28 09:45:15 +02:00

53 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace MailPoet\Util\Notices;
use MailPoet\Newsletter\Renderer\EscapeHelper;
use MailPoet\Services\AuthorizedEmailsController;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions;
use MailPoet\WP\Notice;
class UnauthorizedEmailNotice {
const OPTION_NAME = 'unauthorized-email-addresses-notice';
/** @var SettingsController */
private $settings;
/** @var WPFunctions */
private $wp;
public function __construct(SettingsController $settings, WPFunctions $wp) {
$this->settings = $settings;
$this->wp = $wp;
}
public function init($shouldDisplay) {
$validationError = $this->settings->get(AuthorizedEmailsController::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING);
if ($shouldDisplay && isset($validationError['invalid_sender_address'])) {
return $this->display($validationError);
}
}
public function display($validationError) {
$message = $this->getMessageText($validationError);
$message .= $this->getFixThisButton();
$extraClasses = 'mailpoet-js-error-unauthorized-emails-notice';
Notice::displayError($message, $extraClasses, self::OPTION_NAME, false, false);
}
private function getMessageText($validationError) {
$text = $this->wp->_x('<b>Sending all of your emails has been paused</b> because your email address %s hasnt been authorized yet.</b>',
'Email addresses have to be authorized to be used to send emails. %s will be replaced by an email address.',
'mailpoet');
$message = str_replace('%s', EscapeHelper::escapeHtmlText($validationError['invalid_sender_address']), $text);
return "<p>$message</p>";
}
private function getFixThisButton() {
$button = '<button class="button button-primary mailpoet-js-button-fix-this">' . $this->wp->__('Fix this!', 'mailpoet') . '</button>';
return "<p>$button</p>";
}
}