From f082c065d19f6a65b5410f01c3f602b33772a2e8 Mon Sep 17 00:00:00 2001 From: Jonathan Labreuille Date: Thu, 24 Mar 2016 12:16:02 +0100 Subject: [PATCH] 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) --- assets/js/src/iframe.js | 2 +- lib/Config/Widget.php | 2 +- lib/Models/Subscriber.php | 23 ++++++++++++++------ lib/Subscription/Pages.php | 42 +++++++++++++++++++++++++++++++----- views/settings/advanced.html | 4 +--- 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/assets/js/src/iframe.js b/assets/js/src/iframe.js index 249b608ca1..6ddc2a740e 100644 --- a/assets/js/src/iframe.js +++ b/assets/js/src/iframe.js @@ -1,7 +1,7 @@ define('iframe', ['mailpoet', 'jquery'], function(MailPoet, jQuery) { 'use strict'; MailPoet.Iframe = { - marginY: 15, + marginY: 20, autoSize: function(iframe) { if(!iframe) return; diff --git a/lib/Config/Widget.php b/lib/Config/Widget.php index f8eeef84ba..a0ae7e8666 100644 --- a/lib/Config/Widget.php +++ b/lib/Config/Widget.php @@ -75,8 +75,8 @@ class Widget { ); echo $this->renderer->render('form/iframe.html', $data); - exit(); } + exit(); } } diff --git a/lib/Models/Subscriber.php b/lib/Models/Subscriber.php index 60342a49da..56c40ec72a 100644 --- a/lib/Models/Subscriber.php +++ b/lib/Models/Subscriber.php @@ -118,14 +118,14 @@ class Subscriber extends Model { // set from $from = ( !empty($signup_confirmation['from']) - && !empty($signup_confirmation['from']['email']) + && !empty($signup_confirmation['from']['address']) ) ? $signup_confirmation['from'] : false; // set reply to $reply_to = ( !empty($signup_confirmation['reply_to']) - && !empty($signup_confirmation['reply_to']['email']) + && !empty($signup_confirmation['reply_to']['address']) ) ? $signup_confirmation['reply_to'] : false; @@ -153,6 +153,10 @@ class Subscriber extends Model { return false; } + $signup_confirmation_enabled = (bool)Setting::getValue( + 'signup_confirmation.enabled' + ); + $subscriber = self::createOrUpdate($subscriber_data); $errors = $subscriber->getErrors(); @@ -164,16 +168,21 @@ class Subscriber extends Model { $subscriber->setExpr('deleted_at', 'NULL'); } - if((bool)Setting::getValue('signup_confirmation.enabled')) { - if($subscriber->status !== self::STATUS_SUBSCRIBED) { - $subscriber->sendConfirmationEmail(); - } - } else { + // auto subscribe when signup confirmation is disabled + if($signup_confirmation_enabled === false) { $subscriber->set('status', self::STATUS_SUBSCRIBED); } if($subscriber->save()) { + // link subscriber to segments $subscriber->addToSegments($segment_ids); + + // signup confirmation + if($subscriber->status !== self::STATUS_SUBSCRIBED) { + $subscriber->sendConfirmationEmail(); + } + + // welcome email Scheduler::welcomeForSegmentSubscription($subscriber->id, $segment_ids); } } diff --git a/lib/Subscription/Pages.php b/lib/Subscription/Pages.php index 2a4fb1158b..e2afe1f1af 100644 --- a/lib/Subscription/Pages.php +++ b/lib/Subscription/Pages.php @@ -19,7 +19,7 @@ class Pages { function init() { $action = $this->getAction(); 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('the_title', array($this,'setPageTitle'), 10, 1); add_filter('the_content', array($this,'setPageContent'), 10, 1); @@ -60,8 +60,17 @@ class Pages { return (array_key_exists('mailpoet_preview', $_GET)); } - function setWindowTitle($title) { - return $this->setPageTitle($title); + function setWindowTitle($title, $separator, $separator_location = 'right') { + $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()) { @@ -69,10 +78,23 @@ class Pages { 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 = '') { global $post; - - if($post->post_type === 'mailpoet_page') { + if( + ($this->isMailPoetPage($post->ID) === false) + || + ($page_title !== single_post_title('', false)) + ) { + return $page_title; + } else { $subscriber = $this->getSubscriber(); switch($this->getAction()) { case 'confirm': @@ -98,6 +120,16 @@ class Pages { } function setPageContent($page_content = '[mailpoet_page]') { + global $post; + + if( + ($this->isPreview() === false) + && + ($this->isMailPoetPage($post->ID) === false) + ) { + return $page_content; + } + $content = ''; $subscriber = $this->getSubscriber(); diff --git a/views/settings/advanced.html b/views/settings/advanced.html index 6839d6d6dd..ae366e1dcc 100644 --- a/views/settings/advanced.html +++ b/views/settings/advanced.html @@ -195,9 +195,7 @@ 'action': 'reset' }).done(function(response) { if(response.result === true) { - MailPoet.Notice.success( - "<%= __('MailPoet has been reinstalled successfully using the same version. Settings and data have been deleted.') %>", - { scroll: true }); + window.location = "<%= admin_url('admin.php?page=mailpoet-newsletters') %>"; } else { MailPoet.Notice.error( "<%= __('MailPoet could not be reinstalled. You might need to remove it manually first.') %>",