settings = $settings; $this->wp = $wp; } public function init($shouldDisplay) { if (!$this->settings instanceof SettingsController) { throw new \Exception('This method can only be called if SettingsController is provided'); } $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->getMessage($validationError); $extraClasses = 'mailpoet-js-error-unauthorized-emails-notice'; Notice::displayError($message, $extraClasses, self::OPTION_NAME, false, false); } public function getMessage($validationError) { $message = $this->getMessageText($validationError); $message .= sprintf( '
%s %s %s
', $this->getAuthorizeEmailButton($validationError), $this->getDifferentEmailButton(), $this->getResumeSendingButton($validationError) ); return $message; } private function getMessageText($validationError) { // translators: %s is the email address. $text = _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 getAuthorizeEmailButton($validationError) { $email = $this->wp->escAttr($validationError['invalid_sender_address']); $button = '' . __('Authorize this email address', 'mailpoet') . ''; return $button; } private function getDifferentEmailButton() { $button = ''; return $button; } private function getResumeSendingButton($validationError) { $email = $this->wp->escAttr($validationError['invalid_sender_address']); $button = ''; return $button; } }