Subscription pages
This commit is contained in:
committed by
Vlad
parent
378f6d803a
commit
2cbd2d54f3
@ -278,33 +278,18 @@ const SubscriberList = React.createClass({
|
||||
|
||||
if (subscriber.subscriptions.length > 0) {
|
||||
let subscribed_segments = [];
|
||||
let unsubscribed_segments = [];
|
||||
|
||||
subscriber.subscriptions.map((subscription) => {
|
||||
const segment = this.getSegmentFromId(subscription.segment_id);
|
||||
if(segment === false) return;
|
||||
if (subscription.status === 'subscribed') {
|
||||
subscribed_segments.push(segment.name);
|
||||
} else if (subscription.status === 'unsubscribed') {
|
||||
unsubscribed_segments.push(segment.name);
|
||||
}
|
||||
});
|
||||
segments = (
|
||||
<span>
|
||||
<span className="mailpoet_segments_subscribed">
|
||||
{ subscribed_segments.join(', ') }
|
||||
{
|
||||
(
|
||||
subscribed_segments.length > 0
|
||||
&& unsubscribed_segments.length > 0
|
||||
) ? ' / ' : ''
|
||||
}
|
||||
</span>
|
||||
<span
|
||||
className="mailpoet_segments_unsubscribed"
|
||||
title={MailPoet.I18n.t('listsToWhichSubscriberWasSubscribed')}
|
||||
>
|
||||
{ unsubscribed_segments.join(', ') }
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
|
@ -13,6 +13,7 @@ class Hooks {
|
||||
$this->setupWPUsers();
|
||||
$this->setupImageSize();
|
||||
$this->setupListing();
|
||||
$this->setupManageSubscription();
|
||||
}
|
||||
|
||||
function setupSubscribe() {
|
||||
@ -139,6 +140,18 @@ class Hooks {
|
||||
);
|
||||
}
|
||||
|
||||
function setupManageSubscription() {
|
||||
// handle subscription form submission
|
||||
add_action(
|
||||
'admin_post_mailpoet_subscription_update',
|
||||
'\MailPoet\Subscription\Manage::onSave'
|
||||
);
|
||||
add_action(
|
||||
'admin_post_nopriv_mailpoet_subscription_update',
|
||||
'\MailPoet\Subscription\Manage::onSave'
|
||||
);
|
||||
}
|
||||
|
||||
function setScreenOption($status, $option, $value) {
|
||||
if(preg_match('/^mailpoet_(.*)_per_page$/', $option)) {
|
||||
return $value;
|
||||
|
@ -156,9 +156,6 @@ class Initializer {
|
||||
function setupPages() {
|
||||
$pages = new \MailPoet\Settings\Pages();
|
||||
$pages->init();
|
||||
|
||||
$subscription_pages = new \MailPoet\Subscription\Pages();
|
||||
$subscription_pages->init();
|
||||
}
|
||||
|
||||
function setupShortcodes() {
|
||||
|
@ -74,9 +74,14 @@ class Populator {
|
||||
$mailpoet_page_id = (int)$page->ID;
|
||||
}
|
||||
|
||||
Setting::setValue('subscription.unsubscribe_page', $mailpoet_page_id);
|
||||
Setting::setValue('subscription.manage_page', $mailpoet_page_id);
|
||||
Setting::setValue('subscription.confirmation_page', $mailpoet_page_id);
|
||||
$subscription = Setting::getValue('subscription.pages', array());
|
||||
if(empty($subscription)) {
|
||||
Setting::setValue('subscription.pages', array(
|
||||
'unsubscribe' => $mailpoet_page_id,
|
||||
'manage' => $mailpoet_page_id,
|
||||
'confirmation' => $mailpoet_page_id
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private function createDefaultSettings() {
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\Cron\Daemon;
|
||||
use MailPoet\Subscription;
|
||||
use MailPoet\Statistics\Track\Clicks;
|
||||
use MailPoet\Util\Helpers;
|
||||
|
||||
@ -22,7 +23,11 @@ class PublicAPI {
|
||||
$this->action = isset($_GET['action']) ?
|
||||
Helpers::underscoreToCamelCase($_GET['action']) :
|
||||
false;
|
||||
$this->data = isset($_GET['data']) ? $_GET['data'] : false;
|
||||
$this->data = (
|
||||
(isset($_GET['data']))
|
||||
? unserialize(base64_decode($_GET['data']))
|
||||
: array()
|
||||
);
|
||||
}
|
||||
|
||||
function init() {
|
||||
@ -38,6 +43,14 @@ class PublicAPI {
|
||||
}
|
||||
}
|
||||
|
||||
function subscription() {
|
||||
try {
|
||||
$subscription = new Subscription\Pages($this->action, $this->data);
|
||||
$this->_checkAndCallMethod($subscription, $this->action);
|
||||
} catch(\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
function track() {
|
||||
try {
|
||||
if ($this->action === 'click') {
|
||||
|
@ -3,6 +3,7 @@ namespace MailPoet\Config;
|
||||
use \MailPoet\Models\Newsletter;
|
||||
use \MailPoet\Models\Subscriber;
|
||||
use \MailPoet\Models\SubscriberSegment;
|
||||
use \MailPoet\Subscription;
|
||||
|
||||
class Shortcodes {
|
||||
function __construct() {
|
||||
|
@ -16,12 +16,12 @@ class Daemon {
|
||||
private $timer;
|
||||
|
||||
function __construct($data) {
|
||||
if (!$data) $this->abortWithError(__('Invalid or missing cron data.'));
|
||||
if(empty($data)) $this->abortWithError(__('Invalid or missing cron data.'));
|
||||
set_time_limit(0);
|
||||
ignore_user_abort();
|
||||
$this->daemon = CronHelper::getDaemon();
|
||||
$this->token = CronHelper::createToken();
|
||||
$this->data = unserialize(base64_decode($data));
|
||||
$this->data = $data;
|
||||
$this->timer = microtime(true);
|
||||
}
|
||||
|
||||
|
@ -48,30 +48,6 @@ class Subscriber extends Model {
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
function addToSegments(array $segment_ids = array()) {
|
||||
$wp_users_segment = Segment::getWPUsers();
|
||||
|
||||
if($wp_users_segment !== false) {
|
||||
// delete all relations to segments except WP users
|
||||
SubscriberSegment::where('subscriber_id', $this->id)
|
||||
->whereNotEqual('segment_id', $wp_users_segment->id)
|
||||
->deleteMany();
|
||||
} else {
|
||||
// delete all relations to segments
|
||||
SubscriberSegment::where('subscriber_id', $this->id)->deleteMany();
|
||||
}
|
||||
|
||||
if(!empty($segment_ids)) {
|
||||
$segments = Segment::whereIn('id', $segment_ids)->findMany();
|
||||
foreach($segments as $segment) {
|
||||
$association = SubscriberSegment::create();
|
||||
$association->subscriber_id = $this->id;
|
||||
$association->segment_id = $segment->id;
|
||||
$association->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendConfirmationEmail() {
|
||||
if($this->status === self::STATUS_UNCONFIRMED) {
|
||||
$signup_confirmation = Setting::getValue('signup_confirmation');
|
||||
@ -168,14 +144,18 @@ class Subscriber extends Model {
|
||||
$subscriber->setExpr('deleted_at', 'NULL');
|
||||
}
|
||||
|
||||
if($subscriber->status !== self::STATUS_SUBSCRIBED) {
|
||||
// auto subscribe when signup confirmation is disabled
|
||||
if($signup_confirmation_enabled === false) {
|
||||
if($signup_confirmation_enabled === true) {
|
||||
$subscriber->set('status', self::STATUS_UNCONFIRMED);
|
||||
} else {
|
||||
$subscriber->set('status', self::STATUS_SUBSCRIBED);
|
||||
}
|
||||
}
|
||||
|
||||
if($subscriber->save()) {
|
||||
// link subscriber to segments
|
||||
$subscriber->addToSegments($segment_ids);
|
||||
SubscriberSegment::addSubscriptions($subscriber, $segment_ids);
|
||||
|
||||
// signup confirmation
|
||||
if($subscriber->status !== self::STATUS_SUBSCRIBED) {
|
||||
@ -409,8 +389,8 @@ class Subscriber extends Model {
|
||||
&&
|
||||
($new_status === self::STATUS_UNSUBSCRIBED)
|
||||
) {
|
||||
// make sure we unsubscribe the user from all lists
|
||||
SubscriberSegment::setSubscriptions($subscriber, array());
|
||||
// make sure we unsubscribe the user from all segments
|
||||
SubscriberSegment::removeSubscriptions($subscriber);
|
||||
} else {
|
||||
if($segment_ids !== false) {
|
||||
SubscriberSegment::setSubscriptions($subscriber, $segment_ids);
|
||||
|
@ -16,14 +16,32 @@ class SubscriberSegment extends Model {
|
||||
return $this->has_one(__NAMESPACE__.'\Subscriber', 'id', 'subscriber_id');
|
||||
}
|
||||
|
||||
static function setSubscriptions($subscriber, $segment_ids = array()) {
|
||||
static function removeSubscriptions($subscriber, $segment_ids = array()) {
|
||||
if($subscriber->id > 0) {
|
||||
// unsubscribe from current subscriptions
|
||||
if(!empty($segment_ids)) {
|
||||
// subscribe to segments
|
||||
foreach($segment_ids as $segment_id) {
|
||||
if((int)$segment_id > 0) {
|
||||
self::createOrUpdate(array(
|
||||
'subscriber_id' => $subscriber->id,
|
||||
'segment_id' => $segment_id,
|
||||
'status' => Subscriber::STATUS_UNSUBSCRIBED
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// unsubscribe from all segments
|
||||
SubscriberSegment::where('subscriber_id', $subscriber->id)
|
||||
->findResultSet()
|
||||
->set('status', Subscriber::STATUS_UNSUBSCRIBED)
|
||||
->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function addSubscriptions($subscriber, $segment_ids = array()) {
|
||||
if($subscriber->id > 0) {
|
||||
if(!empty($segment_ids)) {
|
||||
// subscribe to segments
|
||||
foreach($segment_ids as $segment_id) {
|
||||
if((int)$segment_id > 0) {
|
||||
@ -34,9 +52,19 @@ class SubscriberSegment extends Model {
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// subscribe to all segments
|
||||
SubscriberSegment::where('subscriber_id', $subscriber->id)
|
||||
->findResultSet()
|
||||
->set('status', Subscriber::STATUS_SUBSCRIBED)
|
||||
->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $subscriber;
|
||||
static function setSubscriptions($subscriber, $segment_ids = array()) {
|
||||
self::removeSubscriptions($subscriber);
|
||||
self::addSubscriptions($subscriber, $segment_ids);
|
||||
}
|
||||
|
||||
static function subscribed($orm) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoet\Settings;
|
||||
use \MailPoet\Subscription;
|
||||
|
||||
class Pages {
|
||||
function __construct() {
|
||||
@ -65,9 +66,11 @@ class Pages {
|
||||
return array(
|
||||
'id' => $page->ID,
|
||||
'title' => $page->post_title,
|
||||
'preview_url' => add_query_arg(array(
|
||||
'mailpoet_preview' => 1
|
||||
), get_permalink($page->ID))
|
||||
'url' => array(
|
||||
'unsubscribe' => Subscription\Url::getSubscriptionUrl($page, 'unsubscribe'),
|
||||
'manage' => Subscription\Url::getSubscriptionUrl($page, 'manage'),
|
||||
'confirm' => Subscription\Url::getSubscriptionUrl($page, 'confirm')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
32
lib/Subscription/Manage.php
Normal file
32
lib/Subscription/Manage.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace MailPoet\Subscription;
|
||||
use \MailPoet\Models\Setting;
|
||||
use \MailPoet\Models\Subscriber;
|
||||
use \MailPoet\Models\SubscriberSegment;
|
||||
use \MailPoet\Util\Url;
|
||||
|
||||
class Manage {
|
||||
|
||||
static function onSave() {
|
||||
$action = (isset($_POST['action']) ? $_POST['action'] : null);
|
||||
if($action !== 'mailpoet_subscription_update') {
|
||||
Url::redirectBack();
|
||||
}
|
||||
|
||||
$reserved_keywords = array('action', 'mailpoet_redirect');
|
||||
$subscriber_data = array_diff_key(
|
||||
$_POST,
|
||||
array_flip($reserved_keywords)
|
||||
);
|
||||
|
||||
if(isset($subscriber_data['email'])) {
|
||||
if($subscriber_data['email'] !== Pages::DEMO_EMAIL) {
|
||||
$subscriber = Subscriber::createOrUpdate($subscriber_data);
|
||||
$errors = $subscriber->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
// TBD: success/error messages (not present in MP2)
|
||||
Url::redirectBack();
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace MailPoet\Subscription;
|
||||
|
||||
use \MailPoet\Router\Subscribers;
|
||||
use \MailPoet\Models\Subscriber;
|
||||
use \MailPoet\Models\SubscriberSegment;
|
||||
use \MailPoet\Models\CustomField;
|
||||
use \MailPoet\Models\Setting;
|
||||
use \MailPoet\Models\Segment;
|
||||
@ -13,51 +14,123 @@ use \MailPoet\Subscription;
|
||||
class Pages {
|
||||
const DEMO_EMAIL = 'demo@mailpoet.com';
|
||||
|
||||
function __construct() {
|
||||
}
|
||||
private $action;
|
||||
private $data;
|
||||
private $subscriber;
|
||||
|
||||
function init() {
|
||||
$action = $this->getAction();
|
||||
if($action !== null) {
|
||||
function __construct($action, $data) {
|
||||
$this->action = $action;
|
||||
$this->data = $data;
|
||||
$this->subscriber = $this->getSubscriber();
|
||||
|
||||
// handle subscription pages title & content
|
||||
add_filter('wp_title', array($this,'setWindowTitle'), 10, 3);
|
||||
add_filter('document_title_parts', array($this,'setWindowTitleParts'), 10, 1);
|
||||
add_filter('the_title', array($this,'setPageTitle'), 10, 1);
|
||||
add_filter('the_content', array($this,'setPageContent'), 10, 1);
|
||||
|
||||
// manage subscription link shortcode
|
||||
// [mailpoet_manage text="Manage your subscription"]
|
||||
add_shortcode('mailpoet_manage', array($this, 'getManageLink'));
|
||||
}
|
||||
add_action(
|
||||
'admin_post_mailpoet_subscriber_save',
|
||||
array($this, 'subscriberSave')
|
||||
);
|
||||
add_action(
|
||||
'admin_post_nopriv_mailpoet_subscriber_save',
|
||||
array($this, 'subscriberSave')
|
||||
|
||||
private function isPreview() {
|
||||
return (
|
||||
array_key_exists('preview', $_GET)
|
||||
|| array_key_exists('preview', $this->data)
|
||||
);
|
||||
}
|
||||
|
||||
function subscriberSave() {
|
||||
$action = (isset($_POST['action']) ? $_POST['action'] : null);
|
||||
if($action !== 'mailpoet_subscriber_save') {
|
||||
Url::redirectBack();
|
||||
function getSubscriber() {
|
||||
$token = (isset($this->data['token'])) ? $this->data['token'] : null;
|
||||
$email = (isset($this->data['email'])) ? $this->data['email'] : null;
|
||||
|
||||
if(Subscriber::generateToken($email) === $token) {
|
||||
$subscriber = Subscriber::findOne($email);
|
||||
if($subscriber !== false) {
|
||||
return $subscriber;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$reserved_keywords = array('action', 'mailpoet_redirect');
|
||||
$subscriber_data = array_diff_key(
|
||||
$_POST,
|
||||
array_flip($reserved_keywords)
|
||||
);
|
||||
if(isset($subscriber_data['email'])) {
|
||||
if($subscriber_data['email'] !== self::DEMO_EMAIL) {
|
||||
$subscriber = Subscriber::createOrUpdate($subscriber_data);
|
||||
$errors = $subscriber->getErrors();
|
||||
function confirm() {
|
||||
if($this->subscriber !== false) {
|
||||
if($this->subscriber->status !== Subscriber::STATUS_SUBSCRIBED) {
|
||||
$this->subscriber->status = Subscriber::STATUS_SUBSCRIBED;
|
||||
$this->subscriber->save();
|
||||
}
|
||||
}
|
||||
// TBD: success/error messages (not present in MP2)
|
||||
|
||||
Url::redirectBack();
|
||||
}
|
||||
|
||||
function isPreview() {
|
||||
return (array_key_exists('mailpoet_preview', $_GET));
|
||||
function unsubscribe() {
|
||||
if($this->subscriber !== false) {
|
||||
if($this->subscriber->status !== Subscriber::STATUS_UNSUBSCRIBED) {
|
||||
$this->subscriber->status = Subscriber::STATUS_UNSUBSCRIBED;
|
||||
$this->subscriber->save();
|
||||
SubscriberSegment::setSubscriptions($this->subscriber, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
function setPageTitle($page_title = '') {
|
||||
global $post;
|
||||
|
||||
if($post->post_title !== __('MailPoet Page')) return $page_title;
|
||||
if(
|
||||
($this->isMailPoetPage($post->ID) === false)
|
||||
||
|
||||
($page_title !== single_post_title('', false))
|
||||
) {
|
||||
return $page_title;
|
||||
} else {
|
||||
switch($this->action) {
|
||||
case 'confirm':
|
||||
return $this->getConfirmTitle();
|
||||
break;
|
||||
|
||||
case 'manage':
|
||||
|
||||
return $this->getManageTitle();
|
||||
break;
|
||||
|
||||
case 'unsubscribe':
|
||||
return $this->getUnsubscribeTitle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $page_title;
|
||||
}
|
||||
|
||||
function setPageContent($page_content = '[mailpoet_page]') {
|
||||
global $post;
|
||||
|
||||
if(
|
||||
($this->isPreview() === false)
|
||||
&&
|
||||
($this->isMailPoetPage($post->ID) === false)
|
||||
) {
|
||||
return $page_content;
|
||||
}
|
||||
|
||||
$content = '';
|
||||
|
||||
switch($this->action) {
|
||||
case 'confirm':
|
||||
$content = $this->getConfirmContent();
|
||||
break;
|
||||
case 'manage':
|
||||
$content = $this->getManageContent();
|
||||
break;
|
||||
case 'unsubscribe':
|
||||
$content = $this->getUnsubscribeContent();
|
||||
break;
|
||||
}
|
||||
|
||||
if(strpos($page_content, '[mailpoet_page]') !== false) {
|
||||
return str_replace('[mailpoet_page]', $content, $page_content);
|
||||
} else {
|
||||
return $page_content.$content;
|
||||
}
|
||||
}
|
||||
|
||||
function setWindowTitle($title, $separator, $separator_location = 'right') {
|
||||
@ -80,93 +153,24 @@ class Pages {
|
||||
|
||||
function isMailPoetPage($page_id = null) {
|
||||
$mailpoet_page_ids = array_unique(array_values(
|
||||
Setting::getValue('subscription', array())
|
||||
Setting::getValue('subscription.pages', array())
|
||||
));
|
||||
|
||||
return (in_array($page_id, $mailpoet_page_ids));
|
||||
}
|
||||
|
||||
function setPageTitle($page_title = '') {
|
||||
global $post;
|
||||
|
||||
if($post->post_title !== __('MailPoet Page')) return $page_title;
|
||||
|
||||
if(
|
||||
($this->isMailPoetPage($post->ID) === false)
|
||||
||
|
||||
($page_title !== single_post_title('', false))
|
||||
) {
|
||||
return $page_title;
|
||||
} else {
|
||||
$subscriber = $this->getSubscriber();
|
||||
switch($this->getAction()) {
|
||||
case 'confirm':
|
||||
return $this->getConfirmTitle($subscriber);
|
||||
break;
|
||||
|
||||
case 'manage':
|
||||
return $this->getManageTitle($subscriber);
|
||||
break;
|
||||
|
||||
case 'unsubscribe':
|
||||
if($subscriber !== false) {
|
||||
if($subscriber->status !== Subscriber::STATUS_UNSUBSCRIBED) {
|
||||
$subscriber->status = Subscriber::STATUS_UNSUBSCRIBED;
|
||||
$subscriber->save();
|
||||
}
|
||||
}
|
||||
return $this->getUnsubscribeTitle($subscriber);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $page_title;
|
||||
}
|
||||
|
||||
function setPageContent($page_content = '[mailpoet_page]') {
|
||||
global $post;
|
||||
|
||||
if(
|
||||
($this->isPreview() === false)
|
||||
&&
|
||||
($this->isMailPoetPage($post->ID) === false)
|
||||
) {
|
||||
return $page_content;
|
||||
}
|
||||
|
||||
$content = '';
|
||||
$subscriber = $this->getSubscriber();
|
||||
|
||||
switch($this->getAction()) {
|
||||
case 'confirm':
|
||||
$content = $this->getConfirmContent($subscriber);
|
||||
break;
|
||||
case 'manage':
|
||||
$content = $this->getManageContent($subscriber);
|
||||
break;
|
||||
case 'unsubscribe':
|
||||
$content = $this->getUnsubscribeContent($subscriber);
|
||||
break;
|
||||
}
|
||||
return str_replace('[mailpoet_page]', $content, $page_content);
|
||||
}
|
||||
|
||||
private function getConfirmTitle($subscriber) {
|
||||
private function getConfirmTitle() {
|
||||
if($this->isPreview()) {
|
||||
$title = sprintf(
|
||||
__("You've subscribed to: %s"),
|
||||
'demo 1, demo 2'
|
||||
);
|
||||
} else if($subscriber === false) {
|
||||
} else if($this->subscriber === false) {
|
||||
$title = __('Your confirmation link expired, please subscribe again.');
|
||||
} else {
|
||||
if($subscriber->status !== Subscriber::STATUS_SUBSCRIBED) {
|
||||
$subscriber->status = Subscriber::STATUS_SUBSCRIBED;
|
||||
$subscriber->save();
|
||||
}
|
||||
|
||||
$segment_names = array_map(function($segment) {
|
||||
return $segment->name;
|
||||
}, $subscriber->segments()->findMany());
|
||||
}, $this->subscriber->segments()->findMany());
|
||||
|
||||
if(empty($segment_names)) {
|
||||
$title = __("You've subscribed!");
|
||||
@ -180,41 +184,35 @@ class Pages {
|
||||
return $title;
|
||||
}
|
||||
|
||||
private function getManageTitle($subscriber) {
|
||||
if($this->isPreview()) {
|
||||
return sprintf(
|
||||
__('Edit your subscriber profile: %s'),
|
||||
self::DEMO_EMAIL
|
||||
);
|
||||
} else if($subscriber !== false) {
|
||||
return sprintf(
|
||||
__('Edit your subscriber profile: %s'),
|
||||
$subscriber->email
|
||||
);
|
||||
private function getManageTitle() {
|
||||
if($this->isPreview() || $this->subscriber !== false) {
|
||||
return __("Manage your subscription");
|
||||
}
|
||||
}
|
||||
|
||||
private function getUnsubscribeTitle($subscriber) {
|
||||
if($this->isPreview() || $subscriber !== false) {
|
||||
return __("You've unsubscribed!");
|
||||
private function getUnsubscribeTitle() {
|
||||
if($this->isPreview() || $this->subscriber !== false) {
|
||||
return __("You've successfully unsubscribed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function getConfirmContent($subscriber) {
|
||||
if($this->isPreview() || $subscriber !== false) {
|
||||
private function getConfirmContent() {
|
||||
if($this->isPreview() || $this->subscriber !== false) {
|
||||
return __("Yup, we've added you to our list. You'll hear from us shortly.");
|
||||
}
|
||||
}
|
||||
|
||||
private function getManageContent($subscriber) {
|
||||
private function getManageContent() {
|
||||
if($this->isPreview()) {
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate(array(
|
||||
'email' => self::DEMO_EMAIL
|
||||
'email' => self::DEMO_EMAIL,
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe'
|
||||
));
|
||||
} else if($subscriber !== false) {
|
||||
$subscriber = $subscriber
|
||||
} else if($this->subscriber !== false) {
|
||||
$subscriber = $this->subscriber
|
||||
->withCustomFields()
|
||||
->withSubscriptions();
|
||||
} else {
|
||||
@ -238,8 +236,8 @@ class Pages {
|
||||
->findMany();
|
||||
}
|
||||
$subscribed_segment_ids = array();
|
||||
if(!empty($subscriber->subscriptions)) {
|
||||
foreach ($subscriber->subscriptions as $subscription) {
|
||||
if(!empty($this->subscriber->subscriptions)) {
|
||||
foreach ($this->subscriber->subscriptions as $subscription) {
|
||||
if($subscription['status'] === Subscriber::STATUS_SUBSCRIBED) {
|
||||
$subscribed_segment_ids[] = $subscription['segment_id'];
|
||||
}
|
||||
@ -255,16 +253,6 @@ class Pages {
|
||||
}, $segments);
|
||||
|
||||
$fields = array(
|
||||
array(
|
||||
'id' => 'email',
|
||||
'type' => 'text',
|
||||
'params' => array(
|
||||
'label' => __('Email'),
|
||||
'required' => true,
|
||||
'value' => $subscriber->email,
|
||||
'readonly' => true
|
||||
)
|
||||
),
|
||||
array(
|
||||
'id' => 'first_name',
|
||||
'type' => 'text',
|
||||
@ -333,53 +321,54 @@ class Pages {
|
||||
$form_html = '<form method="POST" '.
|
||||
'action="'.admin_url('admin-post.php').'" '.
|
||||
'novalidate>';
|
||||
$form_html .= '<input type="hidden" name="action" '.
|
||||
'value="mailpoet_subscriber_save" />';
|
||||
$form_html .= '<input type="hidden" name="action"'.
|
||||
' value="mailpoet_subscription_update" />';
|
||||
$form_html .= '<input type="hidden" name="segments" value="" />';
|
||||
$form_html .= '<input type="hidden" name="mailpoet_redirect" '.
|
||||
'value="'.Url::getCurrentUrl().'" />';
|
||||
$form_html .= '<input type="hidden" name="email" value="'.$subscriber->email.'" />';
|
||||
|
||||
$form_html .= '<p class="mailpoet_paragraph">';
|
||||
$form_html .= '<label>Email *<br /><strong>'.$subscriber->email.'</strong></label>';
|
||||
$form_html .= '<br /><span style="font-size:85%;">';
|
||||
if($subscriber->wp_user_id !== null) {
|
||||
$form_html .= str_replace(
|
||||
array('[link]', '[/link]'),
|
||||
array('<a href="'.wp_login_url().'" target="_blank">', '</a>'),
|
||||
__('[link]Log in to your account[/link] to update your email.')
|
||||
);
|
||||
} else {
|
||||
$form_html .= __('Need to change your email address? Unsubscribe here and simply sign up again.');
|
||||
}
|
||||
$form_html .= '</span>';
|
||||
$form_html .= '</p>';
|
||||
|
||||
// subscription form
|
||||
$form_html .= \MailPoet\Form\Renderer::renderBlocks($form);
|
||||
$form_html .= '</form>';
|
||||
return $form_html;
|
||||
}
|
||||
|
||||
private function getUnsubscribeContent($subscriber) {
|
||||
private function getUnsubscribeContent() {
|
||||
$content = '';
|
||||
if($this->isPreview() || $subscriber !== false) {
|
||||
$content = '<p>'.__("Great, you'll never hear from us again!").'</p>';
|
||||
if($subscriber !== false) {
|
||||
$content .= '<p><strong>'.
|
||||
str_replace(
|
||||
array('[link]', '[/link]'),
|
||||
array('<a href="'.Subscription\Url::getConfirmationUrl($subscriber).'">', '</a>'),
|
||||
__('You made a mistake? [link]Undo unsubscribe.[/link]')
|
||||
).
|
||||
'</strong></p>';
|
||||
}
|
||||
if($this->isPreview() || $this->subscriber !== false) {
|
||||
$content .= '<p>'.__('You made a mistake?').' <strong>';
|
||||
$content .= '[mailpoet_manage]';
|
||||
$content .= '</strong></p>';
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function getSubscriber() {
|
||||
$token = (isset($_GET['mailpoet_token']))
|
||||
? $_GET['mailpoet_token']
|
||||
: null;
|
||||
$email = (isset($_GET['mailpoet_email']))
|
||||
? $_GET['mailpoet_email']
|
||||
: null;
|
||||
function getManageLink($params) {
|
||||
// get label or display default label
|
||||
$text = (
|
||||
isset($params['text'])
|
||||
? $params['text']
|
||||
: __('Manage your subscription')
|
||||
);
|
||||
|
||||
if(Subscriber::generateToken($email) === $token) {
|
||||
$subscriber = Subscriber::findOne($email);
|
||||
if($subscriber !== false) {
|
||||
return $subscriber;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getAction() {
|
||||
return (isset($_GET['mailpoet_action']))
|
||||
? $_GET['mailpoet_action']
|
||||
: null;
|
||||
return '<a href="'.Subscription\Url::getManageUrl(
|
||||
$this->subscriber
|
||||
).'">'.$text.'</a>';
|
||||
}
|
||||
}
|
@ -6,21 +6,21 @@ use \MailPoet\Models\Setting;
|
||||
|
||||
class Url {
|
||||
static function getConfirmationUrl($subscriber = false) {
|
||||
$post = get_post(Setting::getValue('subscription.confirmation_page'));
|
||||
$post = get_post(Setting::getValue('subscription.pages.confirmation'));
|
||||
return self::getSubscriptionUrl($post, 'confirm', $subscriber);
|
||||
}
|
||||
|
||||
static function getManageUrl($subscriber = false) {
|
||||
$post = get_post(Setting::getValue('subscription.manage_page'));
|
||||
$post = get_post(Setting::getValue('subscription.pages.manage'));
|
||||
return self::getSubscriptionUrl($post, 'manage', $subscriber);
|
||||
}
|
||||
|
||||
static function getUnsubscribeUrl($subscriber = false) {
|
||||
$post = get_post(Setting::getValue('subscription.unsubscribe_page'));
|
||||
$post = get_post(Setting::getValue('subscription.pages.unsubscribe'));
|
||||
return self::getSubscriptionUrl($post, 'unsubscribe', $subscriber);
|
||||
}
|
||||
|
||||
private static function getSubscriptionUrl(
|
||||
static function getSubscriptionUrl(
|
||||
$post = null, $action = null, $subscriber = false
|
||||
) {
|
||||
if($post === null || $action === null) return;
|
||||
@ -28,22 +28,26 @@ class Url {
|
||||
$url = get_permalink($post);
|
||||
|
||||
if($subscriber !== false) {
|
||||
|
||||
if(is_object($subscriber)) {
|
||||
$subscriber = $subscriber->asArray();
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'mailpoet_action='.$action,
|
||||
'mailpoet_token='.Subscriber::generateToken($subscriber['email']),
|
||||
'mailpoet_email='.$subscriber['email']
|
||||
$data = array(
|
||||
'token' => Subscriber::generateToken($subscriber['email']),
|
||||
'email' => $subscriber['email']
|
||||
);
|
||||
} else {
|
||||
$params = array(
|
||||
'mailpoet_action='.$action,
|
||||
'mailpoet_preview=1'
|
||||
$data = array(
|
||||
'preview' => 1
|
||||
);
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'endpoint=subscription',
|
||||
'action='.$action,
|
||||
'data='.base64_encode(serialize($data))
|
||||
);
|
||||
|
||||
// add parameters
|
||||
$url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').join('&', $params);
|
||||
|
||||
|
@ -6,13 +6,7 @@ class Url {
|
||||
}
|
||||
|
||||
static function getCurrentUrl() {
|
||||
global $wp;
|
||||
return home_url(
|
||||
add_query_arg(
|
||||
$wp->query_string,
|
||||
$wp->request
|
||||
)
|
||||
);
|
||||
return home_url(add_query_arg(null, null));
|
||||
}
|
||||
|
||||
static function redirectTo($url = null) {
|
||||
|
@ -209,13 +209,13 @@
|
||||
<select
|
||||
class="mailpoet_page_selection"
|
||||
id="subscription_manage_page"
|
||||
name="subscription[manage_page]"
|
||||
name="subscription[pages][manage]"
|
||||
>
|
||||
<% for page in pages %>
|
||||
<option
|
||||
value="<%= page.id %>"
|
||||
data-preview-url="<%= page.preview_url|raw %>&mailpoet_action=manage"
|
||||
<% if(page.id == settings.subscription.manage_page) %>
|
||||
data-preview-url="<%= page.url.manage|raw %>"
|
||||
<% if(page.id == settings.subscription.pages.manage) %>
|
||||
selected="selected"
|
||||
<% endif %>
|
||||
><%= page.title %></option>
|
||||
@ -256,6 +256,8 @@
|
||||
<%= __('Unsubscribe page') %>
|
||||
<p class="description">
|
||||
<%= __('The page your subscribers see when they click on "Unsubscribe" in your emails.') %>
|
||||
<br />
|
||||
<%= __('Use this shortcode in your own pages: [mailpoet_manage text="Manage your subscription"].') %>
|
||||
</p>
|
||||
</label>
|
||||
</th>
|
||||
@ -264,13 +266,13 @@
|
||||
<select
|
||||
class="mailpoet_page_selection"
|
||||
id="subscription_unsubscribe_page"
|
||||
name="subscription[unsubscribe_page]"
|
||||
name="subscription[pages][unsubscribe]"
|
||||
>
|
||||
<% for page in pages %>
|
||||
<option
|
||||
value="<%= page.id %>"
|
||||
data-preview-url="<%= page.preview_url|raw %>&mailpoet_action=unsubscribe"
|
||||
<% if(page.id == settings.subscription.unsubscribe_page) %>
|
||||
data-preview-url="<%= page.url.unsubscribe|raw %>"
|
||||
<% if(page.id == settings.subscription.pages.unsubscribe) %>
|
||||
selected="selected"
|
||||
<% endif %>
|
||||
><%= page.title %></option>
|
||||
|
@ -151,13 +151,13 @@
|
||||
<p>
|
||||
<select
|
||||
class="mailpoet_page_selection"
|
||||
name="subscription[confirmation_page]"
|
||||
name="subscription[pages][confirmation]"
|
||||
>
|
||||
<% for page in pages %>
|
||||
<option
|
||||
value="<%= page.id %>"
|
||||
data-preview-url="<%= page.preview_url|raw %>&mailpoet_action=confirm"
|
||||
<% if(page.id == settings.subscription.confirmation_page) %>
|
||||
data-preview-url="<%= page.url.confirm|raw %>"
|
||||
<% if(page.id == settings.subscription.pages.confirmation) %>
|
||||
selected="selected"
|
||||
<% endif %>
|
||||
><%= page.title %></option>
|
||||
|
Reference in New Issue
Block a user