Enables [mailpoet_manage] shortcode
Updates code
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberSegment;
|
||||
@@ -9,9 +10,6 @@ use MailPoet\Subscription\Pages;
|
||||
use MailPoet\WP\Hooks;
|
||||
|
||||
class Shortcodes {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function init() {
|
||||
// form widget shortcode
|
||||
add_shortcode('mailpoet_form', array($this, 'formWidget'));
|
||||
@@ -36,16 +34,8 @@ class Shortcodes {
|
||||
$this, 'renderArchiveSubject'
|
||||
), 2, 3);
|
||||
|
||||
// subscription management
|
||||
add_shortcode('mailpoet_manage_subscription', array(
|
||||
$this,
|
||||
'getManageContent'
|
||||
));
|
||||
}
|
||||
|
||||
function getManageContent() {
|
||||
// initialize subscription management shortcodes
|
||||
$subscription_page = new Pages();
|
||||
return $subscription_page->getManageContent();
|
||||
}
|
||||
|
||||
function formWidget($params = array()) {
|
||||
|
@@ -27,16 +27,16 @@ class Subscription {
|
||||
}
|
||||
|
||||
function confirm() {
|
||||
$subscription = new UserSubscription\Pages('confirm', $this->data);
|
||||
$subscription = new UserSubscription\Pages('confirm', $this->data, true);
|
||||
$subscription->confirm();
|
||||
}
|
||||
|
||||
function manage() {
|
||||
$subscription = new UserSubscription\Pages('manage', $this->data);
|
||||
$subscription = new UserSubscription\Pages('manage', $this->data, true);
|
||||
}
|
||||
|
||||
function unsubscribe() {
|
||||
$subscription = new UserSubscription\Pages('unsubscribe', $this->data);
|
||||
$subscription = new UserSubscription\Pages('unsubscribe', $this->data, true);
|
||||
$subscription->unsubscribe();
|
||||
}
|
||||
}
|
@@ -23,32 +23,26 @@ class Pages {
|
||||
private $data;
|
||||
private $subscriber;
|
||||
|
||||
function __construct($action = false, $data = array()) {
|
||||
function __construct($action = false, $data = array(), $init_page_filters = false) {
|
||||
$this->action = $action;
|
||||
$this->data = $data;
|
||||
$this->subscriber = $this->getSubscriber();
|
||||
|
||||
// handle subscription pages title & content
|
||||
if($init_page_filters) {
|
||||
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"]
|
||||
if(!shortcode_exists('mailpoet_manage')) {
|
||||
// manage subscription link shortcodes
|
||||
add_shortcode('mailpoet_manage', array($this, 'getManageLink'));
|
||||
}
|
||||
if(!shortcode_exists('mailpoet_manage_subscription')) {
|
||||
add_shortcode('mailpoet_manage_subscription', array($this, 'getManageContent'));
|
||||
}
|
||||
}
|
||||
|
||||
private function isPreview() {
|
||||
return (
|
||||
array_key_exists('preview', $_GET)
|
||||
|| array_key_exists('preview', $this->data)
|
||||
);
|
||||
return (array_key_exists('preview', $_GET) || array_key_exists('preview', $this->data));
|
||||
}
|
||||
|
||||
function getSubscriber() {
|
||||
@@ -234,7 +228,7 @@ class Pages {
|
||||
->withCustomFields()
|
||||
->withSubscriptions();
|
||||
} else {
|
||||
return __('You need to be logged in or be a subscriber to our mailing lists to see this page.', 'mailpoet');
|
||||
return __('Subscription management form is only available to mailing lists subscribers.', 'mailpoet');
|
||||
}
|
||||
|
||||
$custom_fields = array_map(function($custom_field) use($subscriber) {
|
||||
@@ -418,6 +412,8 @@ class Pages {
|
||||
}
|
||||
|
||||
function getManageLink($params) {
|
||||
if(!$this->subscriber) return __('Link to subscription management page is only available to mailing lists subscribers.', 'mailpoet');
|
||||
|
||||
// get label or display default label
|
||||
$text = (
|
||||
isset($params['text'])
|
||||
|
@@ -52,7 +52,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
expect($request_data['newsletter_hash'])->equals($this->newsletter->hash);
|
||||
}
|
||||
|
||||
function testItDisplaysManageSubscriptionPageForLoggedinExistingUsers() {
|
||||
function testItDisplaysManageSubscriptionFormForLoggedinExistingUsers() {
|
||||
$wp_user = wp_set_current_user(1);
|
||||
expect(is_user_logged_in())->true();
|
||||
$subscriber = Subscriber::create();
|
||||
@@ -60,24 +60,69 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
$subscriber->email = $wp_user->data->user_email;
|
||||
$subscriber->wp_user_id = $wp_user->ID;
|
||||
$subscriber->save();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
$result = do_shortcode('[mailpoet_manage_subscription]');
|
||||
expect($result)->contains('form method="POST"');
|
||||
expect($result)->contains($subscriber->email);
|
||||
}
|
||||
|
||||
function testItDoesNotDisplayManageSubscriptionPageForLoggedinNonexistentSubscribers() {
|
||||
function testItDoesNotDisplayManageSubscriptionFormForLoggedinNonexistentSubscribers() {
|
||||
$wp_user = wp_set_current_user(1);
|
||||
expect(is_user_logged_in())->true();
|
||||
expect(Subscriber::findOne($wp_user->data->user_email))->false();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
$result = do_shortcode('[mailpoet_manage_subscription]');
|
||||
expect($result)->contains('You need to be logged in or be a subscriber to our mailing lists to see this page.');
|
||||
expect($result)->contains('Subscription management form is only available to mailing lists subscribers.');
|
||||
}
|
||||
|
||||
function testItDoesNotDisplayManageSubscriptionFormForLoggedOutUsers() {
|
||||
wp_set_current_user(0);
|
||||
expect(is_user_logged_in())->false();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
$result = do_shortcode('[mailpoet_manage_subscription]');
|
||||
expect($result)->contains('Subscription management form is only available to mailing lists subscribers.');
|
||||
}
|
||||
|
||||
function testItDisplaysLinkToManageSubscriptionPageForLoggedinExistingUsers() {
|
||||
$wp_user = wp_set_current_user(1);
|
||||
expect(is_user_logged_in())->true();
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
||||
$subscriber->email = $wp_user->data->user_email;
|
||||
$subscriber->wp_user_id = $wp_user->ID;
|
||||
$subscriber->save();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
$result = do_shortcode('[mailpoet_manage]');
|
||||
expect($result)->contains('Manage your subscription');
|
||||
}
|
||||
|
||||
function testItDoesNotDisplayLinkToManageSubscriptionPageForLoggedinNonexistentSubscribers() {
|
||||
$wp_user = wp_set_current_user(1);
|
||||
expect(is_user_logged_in())->true();
|
||||
expect(Subscriber::findOne($wp_user->data->user_email))->false();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
$result = do_shortcode('[mailpoet_manage]');
|
||||
expect($result)->contains('Link to subscription management page is only available to mailing lists subscribers.');
|
||||
}
|
||||
|
||||
function testItDoesNotDisplayManageSubscriptionPageForLoggedOutUsers() {
|
||||
wp_set_current_user(0);
|
||||
expect(is_user_logged_in())->false();
|
||||
$result = do_shortcode('[mailpoet_manage_subscription]');
|
||||
expect($result)->contains('You need to be logged in or be a subscriber to our mailing lists to see this page.');
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
$result = do_shortcode('[mailpoet_manage]');
|
||||
expect($result)->contains('Link to subscription management page is only available to mailing lists subscribers.');
|
||||
}
|
||||
|
||||
function _after() {
|
||||
|
Reference in New Issue
Block a user