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->getSettingsButtons($validationError); $message .= $this->getAuthorizationLink($validationError); $message .= $this->getResumeSendingButton(); $extraClasses = 'mailpoet-js-error-unauthorized-emails-notice'; Notice::displayError($message, $extraClasses, self::OPTION_NAME, false, false); } private function getMessageText($validationError) { $text = $this->wp->_x('Sending all of your emails has been paused because your email address %s hasn’t been authorized yet.', '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 "

$message

"; } private function getSettingsButtons($validationError) { $buttons = ''; if (!empty($validationError['invalid_sender_address'])) { $button = $this->wp->_x('Update my Default sender email address', 'Please reuse the current translation of “Default sender”', 'mailpoet'); $button = Helpers::replaceLinkTags("[link]{$button}[/link]", 'admin.php?page=mailpoet-settings', ['class' => 'button button-secondary']); $buttons .= "

$button

"; } return $buttons; } private function getAuthorizationLink($validationError) { $email = $validationError['invalid_sender_address']; $authorizeLink = $this->wp->_x('Authorize %s', 'Link for user to authorize their email address', 'mailpoet'); $authorizeLink = str_replace('%s', EscapeHelper::escapeHtmlText($email), $authorizeLink); $authorizeLink = Helpers::replaceLinkTags("[link]{$authorizeLink}[/link]", 'https://account.mailpoet.com/authorization', ['target' => '_blank']); $html = '

' . $this->wp->_x('OR', 'User has to choose between two options', 'mailpoet') . '

'; $html .= "

$authorizeLink

"; return $html; } private function getResumeSendingButton() { $button = ''; return "

$button

"; } }