Confirmation email + Subscription pages

- form as an iframe: increased marginY
- fixed issue with page titles (old themes using wp_title hook)
- redirect on reinstall instead of showing a message (to avoid being able to re-save old settings)
This commit is contained in:
Jonathan Labreuille
2016-03-24 12:16:02 +01:00
parent 72a9951125
commit f082c065d1
5 changed files with 56 additions and 17 deletions

View File

@ -1,7 +1,7 @@
define('iframe', ['mailpoet', 'jquery'], function(MailPoet, jQuery) { define('iframe', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
'use strict'; 'use strict';
MailPoet.Iframe = { MailPoet.Iframe = {
marginY: 15, marginY: 20,
autoSize: function(iframe) { autoSize: function(iframe) {
if(!iframe) return; if(!iframe) return;

View File

@ -75,8 +75,8 @@ class Widget {
); );
echo $this->renderer->render('form/iframe.html', $data); echo $this->renderer->render('form/iframe.html', $data);
exit();
} }
exit();
} }
} }

View File

@ -118,14 +118,14 @@ class Subscriber extends Model {
// set from // set from
$from = ( $from = (
!empty($signup_confirmation['from']) !empty($signup_confirmation['from'])
&& !empty($signup_confirmation['from']['email']) && !empty($signup_confirmation['from']['address'])
) ? $signup_confirmation['from'] ) ? $signup_confirmation['from']
: false; : false;
// set reply to // set reply to
$reply_to = ( $reply_to = (
!empty($signup_confirmation['reply_to']) !empty($signup_confirmation['reply_to'])
&& !empty($signup_confirmation['reply_to']['email']) && !empty($signup_confirmation['reply_to']['address'])
) ? $signup_confirmation['reply_to'] ) ? $signup_confirmation['reply_to']
: false; : false;
@ -153,6 +153,10 @@ class Subscriber extends Model {
return false; return false;
} }
$signup_confirmation_enabled = (bool)Setting::getValue(
'signup_confirmation.enabled'
);
$subscriber = self::createOrUpdate($subscriber_data); $subscriber = self::createOrUpdate($subscriber_data);
$errors = $subscriber->getErrors(); $errors = $subscriber->getErrors();
@ -164,16 +168,21 @@ class Subscriber extends Model {
$subscriber->setExpr('deleted_at', 'NULL'); $subscriber->setExpr('deleted_at', 'NULL');
} }
if((bool)Setting::getValue('signup_confirmation.enabled')) { // auto subscribe when signup confirmation is disabled
if($subscriber->status !== self::STATUS_SUBSCRIBED) { if($signup_confirmation_enabled === false) {
$subscriber->sendConfirmationEmail();
}
} else {
$subscriber->set('status', self::STATUS_SUBSCRIBED); $subscriber->set('status', self::STATUS_SUBSCRIBED);
} }
if($subscriber->save()) { if($subscriber->save()) {
// link subscriber to segments
$subscriber->addToSegments($segment_ids); $subscriber->addToSegments($segment_ids);
// signup confirmation
if($subscriber->status !== self::STATUS_SUBSCRIBED) {
$subscriber->sendConfirmationEmail();
}
// welcome email
Scheduler::welcomeForSegmentSubscription($subscriber->id, $segment_ids); Scheduler::welcomeForSegmentSubscription($subscriber->id, $segment_ids);
} }
} }

View File

@ -19,7 +19,7 @@ class Pages {
function init() { function init() {
$action = $this->getAction(); $action = $this->getAction();
if($action !== null) { if($action !== null) {
add_filter('wp_title', array($this,'setWindowTitle'), 10, 1); add_filter('wp_title', array($this,'setWindowTitle'), 10, 3);
add_filter('document_title_parts', array($this,'setWindowTitleParts'), 10, 1); add_filter('document_title_parts', array($this,'setWindowTitleParts'), 10, 1);
add_filter('the_title', array($this,'setPageTitle'), 10, 1); add_filter('the_title', array($this,'setPageTitle'), 10, 1);
add_filter('the_content', array($this,'setPageContent'), 10, 1); add_filter('the_content', array($this,'setPageContent'), 10, 1);
@ -60,8 +60,17 @@ class Pages {
return (array_key_exists('mailpoet_preview', $_GET)); return (array_key_exists('mailpoet_preview', $_GET));
} }
function setWindowTitle($title) { function setWindowTitle($title, $separator, $separator_location = 'right') {
return $this->setPageTitle($title); $title_parts = explode(" $separator ", $title);
if($separator_location === 'right') {
// first part
$title_parts[0] = $this->setPageTitle($title_parts[0]);
} else {
// last part
$last_index = count($title_parts) - 1;
$title_parts[$last_index] = $this->setPageTitle($title_parts[$last_index]);
}
return implode(" $separator ", $title_parts);
} }
function setWindowTitleParts($meta = array()) { function setWindowTitleParts($meta = array()) {
@ -69,10 +78,23 @@ class Pages {
return $meta; return $meta;
} }
function isMailPoetPage($page_id = null) {
$mailpoet_page_ids = array_unique(array_values(
Setting::getValue('subscription', array())
));
return (in_array($page_id, $mailpoet_page_ids));
}
function setPageTitle($page_title = '') { function setPageTitle($page_title = '') {
global $post; global $post;
if(
if($post->post_type === 'mailpoet_page') { ($this->isMailPoetPage($post->ID) === false)
||
($page_title !== single_post_title('', false))
) {
return $page_title;
} else {
$subscriber = $this->getSubscriber(); $subscriber = $this->getSubscriber();
switch($this->getAction()) { switch($this->getAction()) {
case 'confirm': case 'confirm':
@ -98,6 +120,16 @@ class Pages {
} }
function setPageContent($page_content = '[mailpoet_page]') { function setPageContent($page_content = '[mailpoet_page]') {
global $post;
if(
($this->isPreview() === false)
&&
($this->isMailPoetPage($post->ID) === false)
) {
return $page_content;
}
$content = ''; $content = '';
$subscriber = $this->getSubscriber(); $subscriber = $this->getSubscriber();

View File

@ -195,9 +195,7 @@
'action': 'reset' 'action': 'reset'
}).done(function(response) { }).done(function(response) {
if(response.result === true) { if(response.result === true) {
MailPoet.Notice.success( window.location = "<%= admin_url('admin.php?page=mailpoet-newsletters') %>";
"<%= __('MailPoet has been reinstalled successfully using the same version. Settings and data have been deleted.') %>",
{ scroll: true });
} else { } else {
MailPoet.Notice.error( MailPoet.Notice.error(
"<%= __('MailPoet could not be reinstalled. You might need to remove it manually first.') %>", "<%= __('MailPoet could not be reinstalled. You might need to remove it manually first.') %>",