properly handle custom subscriptions pages
This commit is contained in:
@@ -35,8 +35,4 @@ class SendingQueue extends Model {
|
|||||||
$this->save();
|
$this->save();
|
||||||
return ($this->getErrors() === false && $this->id() > 0);
|
return ($this->getErrors() === false && $this->id() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop() {
|
|
||||||
return $this->delete();
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -33,7 +33,7 @@ class Pages {
|
|||||||
'post_type' => 'mailpoet_page',
|
'post_type' => 'mailpoet_page',
|
||||||
'post_author' => 1,
|
'post_author' => 1,
|
||||||
'post_content' => '[mailpoet_page]',
|
'post_content' => '[mailpoet_page]',
|
||||||
'post_title' => __('MailPoet Page'),
|
'post_title' => '[mailpoet_title]',
|
||||||
'post_name' => 'subscriptions'
|
'post_name' => 'subscriptions'
|
||||||
));
|
));
|
||||||
flush_rewrite_rules();
|
flush_rewrite_rules();
|
||||||
@@ -66,7 +66,7 @@ class Pages {
|
|||||||
'id' => $page->ID,
|
'id' => $page->ID,
|
||||||
'title' => $page->post_title,
|
'title' => $page->post_title,
|
||||||
'preview_url' => add_query_arg(array(
|
'preview_url' => add_query_arg(array(
|
||||||
'preview' => 1
|
'mailpoet_preview' => 1
|
||||||
), get_permalink($page->ID))
|
), get_permalink($page->ID))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -17,10 +17,11 @@ class Pages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if(isset($_GET['mailpoet_page'])) {
|
$action = $this->getAction();
|
||||||
add_filter('wp_title', array($this,'setWindowTitle'));
|
if($action !== null) {
|
||||||
add_filter('the_title', array($this,'setPageTitle'));
|
add_filter('document_title_parts', array($this,'setWindowTitle'), 10, 1);
|
||||||
add_filter('the_content', array($this,'setPageContent'));
|
add_filter('the_title', array($this,'setPageTitle'), 10, 1);
|
||||||
|
add_filter('the_content', array($this,'setPageContent'), 10, 1);
|
||||||
}
|
}
|
||||||
add_action(
|
add_action(
|
||||||
'admin_post_mailpoet_subscriber_save',
|
'admin_post_mailpoet_subscriber_save',
|
||||||
@@ -43,45 +44,56 @@ class Pages {
|
|||||||
$_POST,
|
$_POST,
|
||||||
array_flip($reserved_keywords)
|
array_flip($reserved_keywords)
|
||||||
);
|
);
|
||||||
$subscriber = Subscriber::createOrUpdate($subscriber_data);
|
if(isset($subscriber_data['email'])) {
|
||||||
$errors = $subscriber->getErrors();
|
if($subscriber_data['email'] !== self::DEMO_EMAIL) {
|
||||||
|
$subscriber = Subscriber::createOrUpdate($subscriber_data);
|
||||||
|
$errors = $subscriber->getErrors();
|
||||||
|
}
|
||||||
|
}
|
||||||
// TBD: success/error messages (not present in MP2)
|
// TBD: success/error messages (not present in MP2)
|
||||||
|
|
||||||
Url::redirectBack();
|
Url::redirectBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPreview() {
|
function isPreview() {
|
||||||
return (array_key_exists('preview', $_GET));
|
return (array_key_exists('mailpoet_preview', $_GET));
|
||||||
}
|
}
|
||||||
|
|
||||||
function setWindowTitle() {
|
function setWindowTitle($meta = array()) {
|
||||||
// TODO
|
$meta['title'] = $this->setPageTitle($meta['title']);
|
||||||
|
return $meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPageTitle($title = null) {
|
function setPageTitle($page_title = '[mailpoet_title]') {
|
||||||
$subscriber = $this->getSubscriber();
|
if(
|
||||||
|
(strpos($page_title, '[mailpoet_title]') === false)
|
||||||
|
&&
|
||||||
|
(strlen(trim($page_title)) > 0)
|
||||||
|
) {
|
||||||
|
return $page_title;
|
||||||
|
} else {
|
||||||
|
$subscriber = $this->getSubscriber();
|
||||||
|
switch($this->getAction()) {
|
||||||
|
case 'confirm':
|
||||||
|
return $this->getConfirmTitle($subscriber);
|
||||||
|
break;
|
||||||
|
|
||||||
switch($this->getAction()) {
|
case 'manage':
|
||||||
case 'confirm':
|
return $this->getManageTitle($subscriber);
|
||||||
return $this->getConfirmTitle($subscriber);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'manage':
|
case 'unsubscribe':
|
||||||
return $this->getManageTitle($subscriber);
|
if($subscriber !== false) {
|
||||||
break;
|
if($subscriber->status !== Subscriber::STATUS_UNSUBSCRIBED) {
|
||||||
|
$subscriber->status = Subscriber::STATUS_UNSUBSCRIBED;
|
||||||
case 'unsubscribe':
|
$subscriber->save();
|
||||||
if($subscriber !== false) {
|
}
|
||||||
if($subscriber->status !== Subscriber::STATUS_UNSUBSCRIBED) {
|
|
||||||
$subscriber->status = Subscriber::STATUS_UNSUBSCRIBED;
|
|
||||||
$subscriber->save();
|
|
||||||
}
|
}
|
||||||
}
|
return $this->getUnsubscribeTitle($subscriber);
|
||||||
return $this->getUnsubscribeTitle($subscriber);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
return $title;
|
return str_replace('[mailpoet_title]', $title, $page_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPageContent($page_content = '[mailpoet_page]') {
|
function setPageContent($page_content = '[mailpoet_page]') {
|
||||||
|
@@ -41,7 +41,7 @@ class Url {
|
|||||||
} else {
|
} else {
|
||||||
$params = array(
|
$params = array(
|
||||||
'mailpoet_action='.$action,
|
'mailpoet_action='.$action,
|
||||||
'preview'
|
'mailpoet_preview=1'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// add parameters
|
// add parameters
|
||||||
|
Reference in New Issue
Block a user