Add confirm unsubscribe page
[MAILPOET-2736]
This commit is contained in:
committed by
Veljko V
parent
63600e27ac
commit
66f2308e41
@ -12,12 +12,14 @@ class Subscription {
|
||||
const ACTION_CONFIRM = 'confirm';
|
||||
const ACTION_MANAGE = 'manage';
|
||||
const ACTION_UNSUBSCRIBE = 'unsubscribe';
|
||||
const ACTION_CONFIRM_UNSUBSCRIBE = 'confirmUnsubscribe';
|
||||
public $allowedActions = [
|
||||
self::ACTION_CAPTCHA,
|
||||
self::ACTION_CAPTCHA_IMAGE,
|
||||
self::ACTION_CONFIRM,
|
||||
self::ACTION_MANAGE,
|
||||
self::ACTION_UNSUBSCRIBE,
|
||||
self::ACTION_CONFIRM_UNSUBSCRIBE,
|
||||
];
|
||||
public $permissions = [
|
||||
'global' => AccessControl::NO_ACCESS_RESTRICTION,
|
||||
@ -47,6 +49,10 @@ class Subscription {
|
||||
$subscription->confirm();
|
||||
}
|
||||
|
||||
public function confirmUnsubscribe($data) {
|
||||
$this->initSubscriptionPage(UserSubscription\Pages::ACTION_CONFIRM_UNSUBSCRIBE, $data);
|
||||
}
|
||||
|
||||
public function manage($data) {
|
||||
$this->initSubscriptionPage(UserSubscription\Pages::ACTION_MANAGE, $data);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace MailPoet\Subscription;
|
||||
|
||||
use MailPoet\Config\Renderer as TemplateRenderer;
|
||||
use MailPoet\Form\AssetsController;
|
||||
use MailPoet\Form\Block\Date as FormBlockDate;
|
||||
use MailPoet\Form\Renderer as FormRenderer;
|
||||
@ -21,6 +22,7 @@ class Pages {
|
||||
const DEMO_EMAIL = 'demo@mailpoet.com';
|
||||
const ACTION_CAPTCHA = 'captcha';
|
||||
const ACTION_CONFIRM = 'confirm';
|
||||
const ACTION_CONFIRM_UNSUBSCRIBE = 'confirm_unsubscribe';
|
||||
const ACTION_MANAGE = 'manage';
|
||||
const ACTION_UNSUBSCRIBE = 'unsubscribe';
|
||||
|
||||
@ -61,6 +63,9 @@ class Pages {
|
||||
/** @var FormBlockDate */
|
||||
private $dateBlock;
|
||||
|
||||
/** @var TemplateRenderer */
|
||||
private $templateRenderer;
|
||||
|
||||
public function __construct(
|
||||
NewSubscriberNotificationMailer $newSubscriberNotificationSender,
|
||||
WPFunctions $wp,
|
||||
@ -72,7 +77,8 @@ class Pages {
|
||||
SubscriptionUrlFactory $subscriptionUrlFactory,
|
||||
AssetsController $assetsController,
|
||||
FormRenderer $formRenderer,
|
||||
FormBlockDate $dateBlock
|
||||
FormBlockDate $dateBlock,
|
||||
TemplateRenderer $templateRenderer
|
||||
) {
|
||||
$this->wp = $wp;
|
||||
$this->newSubscriberNotificationSender = $newSubscriberNotificationSender;
|
||||
@ -85,6 +91,7 @@ class Pages {
|
||||
$this->assetsController = $assetsController;
|
||||
$this->formRenderer = $formRenderer;
|
||||
$this->dateBlock = $dateBlock;
|
||||
$this->templateRenderer = $templateRenderer;
|
||||
}
|
||||
|
||||
public function init($action = false, $data = [], $initShortcodes = false, $initPageFilters = false) {
|
||||
@ -209,6 +216,9 @@ class Pages {
|
||||
case self::ACTION_CONFIRM:
|
||||
return $this->getConfirmTitle();
|
||||
|
||||
case self::ACTION_CONFIRM_UNSUBSCRIBE:
|
||||
return $this->getConfirmUnsubscribeTitle();
|
||||
|
||||
case self::ACTION_MANAGE:
|
||||
return $this->getManageTitle();
|
||||
|
||||
@ -238,6 +248,9 @@ class Pages {
|
||||
case self::ACTION_CONFIRM:
|
||||
$content = $this->getConfirmContent();
|
||||
break;
|
||||
case self::ACTION_CONFIRM_UNSUBSCRIBE:
|
||||
$content = $this->getConfirmUnsubscribeContent();
|
||||
break;
|
||||
case self::ACTION_MANAGE:
|
||||
$content = $this->getManageContent();
|
||||
break;
|
||||
@ -307,6 +320,12 @@ class Pages {
|
||||
}
|
||||
}
|
||||
|
||||
private function getConfirmUnsubscribeTitle() {
|
||||
if ($this->isPreview() || $this->subscriber !== false) {
|
||||
return $this->wp->__("Confirm you want to unsubscribe.", 'mailpoet');
|
||||
}
|
||||
}
|
||||
|
||||
private function getConfirmContent() {
|
||||
if ($this->isPreview() || $this->subscriber !== false) {
|
||||
return $this->wp->__("Yup, we've added you to our email list. You'll hear from us shortly.", 'mailpoet');
|
||||
@ -524,6 +543,13 @@ class Pages {
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function getConfirmUnsubscribeContent() {
|
||||
$templateData = [
|
||||
'unsubscribeUrl' => $this->subscriptionUrlFactory->getUnsubscribeUrl($this->subscriber),
|
||||
];
|
||||
return $this->templateRenderer->render('subscription/confirm_unsubscribe.html', $templateData);
|
||||
}
|
||||
|
||||
public function getManageLink($params) {
|
||||
if (!$this->subscriber) return $this->wp->__('Link to subscription management page is only available to mailing lists subscribers.', 'mailpoet');
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Test\Subscription;
|
||||
|
||||
use Codeception\Stub;
|
||||
use Codeception\Util\Fixtures;
|
||||
use MailPoet\Config\Renderer;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Form\AssetsController;
|
||||
use MailPoet\Form\Block\Date as FormBlockDate;
|
||||
@ -178,7 +179,8 @@ class PagesTest extends \MailPoetTest {
|
||||
$container->get(SubscriptionUrlFactory::class),
|
||||
$container->get(AssetsController::class),
|
||||
$container->get(FormRenderer::class),
|
||||
$container->get(FormBlockDate::class)
|
||||
$container->get(FormBlockDate::class),
|
||||
$container->get(Renderer::class)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
7
views/subscription/confirm_unsubscribe.html
Normal file
7
views/subscription/confirm_unsubscribe.html
Normal file
@ -0,0 +1,7 @@
|
||||
<% block content %>
|
||||
<p class="mailpoet_confirm_unsubscribe">
|
||||
<%= __('Simply click on this link to stop receiving emails from us.') %>
|
||||
<br>
|
||||
<a href="<%= unsubscribeUrl %>"><%= _x('Yes, unsubscribe me', 'Text in unsubscribe link') %></a>
|
||||
</p>
|
||||
<% endblock %>
|
Reference in New Issue
Block a user