Subscribe in comments
- added Subscriber::subscribe($user, $segment_ids) - refactored Router\Subscribers->subscribe() method to account for new method - added Form\Subscribe class to handle subscription in comments - updated Basics settings page (changed "list" to "segment")
This commit is contained in:
@@ -19,6 +19,8 @@ a:focus
|
|||||||
|
|
||||||
// select 2
|
// select 2
|
||||||
.select2-container
|
.select2-container
|
||||||
|
width: 25em !important
|
||||||
|
|
||||||
// textareas
|
// textareas
|
||||||
textarea.regular-text
|
textarea.regular-text
|
||||||
width: 25em !important
|
width: 25em !important
|
||||||
|
@@ -1,11 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
use \MailPoet\Models\Setting;
|
||||||
|
|
||||||
class Hooks {
|
class Hooks {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
$subscribe_settings = Setting::getValue('subscribe');
|
||||||
|
|
||||||
|
if($subscribe_settings !== null) {
|
||||||
|
// Subscribe in comments
|
||||||
|
if(
|
||||||
|
isset($subscribe_settings['on_comment']['enabled'])
|
||||||
|
&& $subscribe_settings['on_comment']['enabled']
|
||||||
|
) {
|
||||||
|
add_action(
|
||||||
|
'comment_form',
|
||||||
|
'\MailPoet\Form\Subscribe::inComments'
|
||||||
|
);
|
||||||
|
add_action(
|
||||||
|
'comment_post',
|
||||||
|
'\MailPoet\Form\Subscribe::onCommentSubmit',
|
||||||
|
60,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
add_action(
|
||||||
|
'wp_set_comment_status',
|
||||||
|
'\MailPoet\Form\Subscribe::onCommentStatusUpdate',
|
||||||
|
60,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WP Users synchronization
|
// WP Users synchronization
|
||||||
add_action(
|
add_action(
|
||||||
'user_register',
|
'user_register',
|
||||||
|
@@ -240,6 +240,7 @@ class Menu {
|
|||||||
|
|
||||||
function settings() {
|
function settings() {
|
||||||
$settings = Setting::getAll();
|
$settings = Setting::getAll();
|
||||||
|
$flags = $this->_getFlags();
|
||||||
|
|
||||||
// dkim: check if public/private keys have been generated
|
// dkim: check if public/private keys have been generated
|
||||||
if(
|
if(
|
||||||
@@ -258,10 +259,9 @@ class Menu {
|
|||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
'segments' => Segment::getPublished()
|
'segments' => Segment::getPublic()->findArray(),
|
||||||
->findArray(),
|
|
||||||
'pages' => Pages::getAll(),
|
'pages' => Pages::getAll(),
|
||||||
'flags' => $this->_getFlags(),
|
'flags' => $flags,
|
||||||
'charsets' => Charsets::getAll(),
|
'charsets' => Charsets::getAll(),
|
||||||
'current_user' => wp_get_current_user(),
|
'current_user' => wp_get_current_user(),
|
||||||
'permissions' => Permissions::getAll(),
|
'permissions' => Permissions::getAll(),
|
||||||
|
92
lib/Form/Subscribe.php
Normal file
92
lib/Form/Subscribe.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\Form;
|
||||||
|
use \MailPoet\Models\Setting;
|
||||||
|
use \MailPoet\Models\Subscriber;
|
||||||
|
|
||||||
|
class Subscribe {
|
||||||
|
static function inComments() {
|
||||||
|
$label = (isset($subscribe_settings['on_comment']['label'])
|
||||||
|
? $subscribe_settings['on_comment']['label']
|
||||||
|
: __('Yes, add me to your mailing list.')
|
||||||
|
);
|
||||||
|
|
||||||
|
$html = <<<EOL
|
||||||
|
<p class="comment-form-mailpoet">
|
||||||
|
<label for="mailpoet_subscribe_on_comment">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="mailpoet_subscribe_on_comment"
|
||||||
|
value="1"
|
||||||
|
name="mailpoet[subscribe_on_comment]"
|
||||||
|
/> $label
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
EOL;
|
||||||
|
echo $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function onCommentSubmit($comment_id, $comment_approved) {
|
||||||
|
if($comment_approved === 'spam') return;
|
||||||
|
|
||||||
|
if(
|
||||||
|
isset($_POST['mailpoet']['subscribe_on_comment'])
|
||||||
|
&&
|
||||||
|
filter_var(
|
||||||
|
$_POST['mailpoet']['subscribe_on_comment'],
|
||||||
|
FILTER_VALIDATE_BOOLEAN
|
||||||
|
) === true
|
||||||
|
) {
|
||||||
|
if($comment_approved === 0) {
|
||||||
|
add_comment_meta(
|
||||||
|
$comment_id,
|
||||||
|
'mailpoet',
|
||||||
|
'subscribe_on_comment',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$subscribe_settings = Setting::getValue('subscribe');
|
||||||
|
$segment_ids = (array)$subscribe_settings['on_comment']['segments'];
|
||||||
|
|
||||||
|
if($subscribe_settings !== null) {
|
||||||
|
$comment = get_comment($comment_id);
|
||||||
|
|
||||||
|
$result = Subscriber::subscribe(
|
||||||
|
array(
|
||||||
|
'email' => $comment->comment_author_email,
|
||||||
|
'first_name' => $comment->comment_author
|
||||||
|
),
|
||||||
|
$segment_ids
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function onCommentStatusUpdate($comment_id, $comment_status) {
|
||||||
|
$comment_meta = get_comment_meta(
|
||||||
|
$comment_id,
|
||||||
|
'mailpoet',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
if(
|
||||||
|
$comment_status ==='approve'
|
||||||
|
&& $comment_meta === 'subscribe_on_comment'
|
||||||
|
) {
|
||||||
|
$subscribe_settings = Setting::getValue('subscribe');
|
||||||
|
$segment_ids = (array)$subscribe_settings['on_comment']['segments'];
|
||||||
|
|
||||||
|
if($subscribe_settings !== null) {
|
||||||
|
$comment = get_comment($comment_id);
|
||||||
|
|
||||||
|
Subscriber::subscribe(
|
||||||
|
array(
|
||||||
|
'email' => $comment->comment_author_email,
|
||||||
|
'first_name' => $comment->comment_author
|
||||||
|
),
|
||||||
|
$segment_ids
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -32,6 +32,65 @@ class Subscriber extends Model {
|
|||||||
return parent::delete();
|
return parent::delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addToSegments(array $segment_ids = array()) {
|
||||||
|
$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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function subscribe($subscriber_data = array(), $segment_ids = array()) {
|
||||||
|
if(empty($subscriber_data) or empty($segment_ids)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$subscriber = static::createOrUpdate($subscriber_data);
|
||||||
|
|
||||||
|
if($subscriber !== false && $subscriber->id() > 0) {
|
||||||
|
$signup_confirmation = Setting::getValue('signup_confirmation', array());
|
||||||
|
$has_signup_confirmation = true;
|
||||||
|
if(array_key_exists('enabled', $signup_confirmation)) {
|
||||||
|
$has_signup_confirmation = filter_var(
|
||||||
|
$signup_confirmation['enabled'],
|
||||||
|
FILTER_VALIDATE_BOOLEAN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore deleted subscriber
|
||||||
|
if($subscriber->deleted_at !== NULL) {
|
||||||
|
$subscriber->setExpr('deleted_at', 'NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($has_signup_confirmation === false) {
|
||||||
|
// auto subscribe when signup confirmation is turned off
|
||||||
|
$subscriber->set('status', 'subscribed');
|
||||||
|
} else {
|
||||||
|
// reset status of existing subscribers if signup confirmation
|
||||||
|
// is turned on
|
||||||
|
if($subscriber->isNew() === false) {
|
||||||
|
// existing subscriber
|
||||||
|
if($subscriber->status !== 'subscribed') {
|
||||||
|
$subscriber->set('status', 'unconfirmed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// send confirmation email to unconfirmed subscribers
|
||||||
|
if($subscriber->status === 'unconfirmed') {
|
||||||
|
// TODO: send signup confirmation email
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($subscriber->save()) {
|
||||||
|
$subscriber->addToSegments($segment_ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $subscriber;
|
||||||
|
}
|
||||||
|
|
||||||
static function search($orm, $search = '') {
|
static function search($orm, $search = '') {
|
||||||
if(strlen(trim($search) === 0)) {
|
if(strlen(trim($search) === 0)) {
|
||||||
return $orm;
|
return $orm;
|
||||||
@@ -181,17 +240,52 @@ class Subscriber extends Model {
|
|||||||
$subscriber = false;
|
$subscriber = false;
|
||||||
|
|
||||||
if(isset($data['id']) && (int)$data['id'] > 0) {
|
if(isset($data['id']) && (int)$data['id'] > 0) {
|
||||||
$subscriber = self::findOne((int)$data['id']);
|
$subscriber = static::findOne((int)$data['id']);
|
||||||
unset($data['id']);
|
unset($data['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($subscriber === false && !empty($data['email'])) {
|
||||||
|
$subscriber = static::where('email', $data['email'])->findOne();
|
||||||
|
if($subscriber !== false) {
|
||||||
|
unset($data['email']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($subscriber === false) {
|
if($subscriber === false) {
|
||||||
$subscriber = self::create();
|
$subscriber = static::create();
|
||||||
$subscriber->hydrate($data);
|
$subscriber->hydrate($data);
|
||||||
} else {
|
} else {
|
||||||
$subscriber->set($data);
|
$subscriber->set($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Cf
|
||||||
|
/*
|
||||||
|
// custom fields
|
||||||
|
$custom_fields = array();
|
||||||
|
foreach($data as $key => $value) {
|
||||||
|
if(strpos($key, 'cf_') === 0) {
|
||||||
|
$custom_fields[substr($key, 3)] = $value;
|
||||||
|
unset($data[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add custom fields
|
||||||
|
if(!empty($custom_fields)) {
|
||||||
|
foreach($custom_fields as $custom_field_id => $value) {
|
||||||
|
if(is_array($value)) {
|
||||||
|
// date
|
||||||
|
$value = mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
|
||||||
|
}
|
||||||
|
$subscriber_custom_field = SubscriberCustomField::create();
|
||||||
|
$subscriber_custom_field->hydrate(array(
|
||||||
|
'subscriber_id' => $subscriber->id(),
|
||||||
|
'custom_field_id' => $custom_field_id,
|
||||||
|
'value' => $value
|
||||||
|
));
|
||||||
|
$subscriber_custom_field->save();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
return $subscriber;
|
return $subscriber;
|
||||||
}
|
}
|
||||||
|
@@ -68,10 +68,10 @@ class Subscribers {
|
|||||||
function save($data = array()) {
|
function save($data = array()) {
|
||||||
$errors = array();
|
$errors = array();
|
||||||
$result = false;
|
$result = false;
|
||||||
$segments = false;
|
$segment_ids = array();
|
||||||
|
|
||||||
if(array_key_exists('segments', $data)) {
|
if(array_key_exists('segments', $data)) {
|
||||||
$segments = $data['segments'];
|
$segment_ids = (array)$data['segments'];
|
||||||
unset($data['segments']);
|
unset($data['segments']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,18 +82,8 @@ class Subscribers {
|
|||||||
} else {
|
} else {
|
||||||
$result = true;
|
$result = true;
|
||||||
|
|
||||||
if($segments !== false) {
|
if(!empty($segment_ids)) {
|
||||||
SubscriberSegment::where('subscriber_id', $subscriber->id)
|
$subscriber->addToSegments($segment_ids);
|
||||||
->deleteMany();
|
|
||||||
|
|
||||||
if(!empty($segments)) {
|
|
||||||
foreach($segments as $segment_id) {
|
|
||||||
$relation = SubscriberSegment::create();
|
|
||||||
$relation->segment_id = $segment_id;
|
|
||||||
$relation->subscriber_id = $subscriber->id;
|
|
||||||
$relation->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wp_send_json(array(
|
wp_send_json(array(
|
||||||
@@ -112,109 +102,31 @@ class Subscribers {
|
|||||||
$errors[] = __('This form does not exist.');
|
$errors[] = __('This form does not exist.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($data['segments'])) {
|
$segment_ids = (!empty($data['segments'])
|
||||||
$errors[] = __('You need to select a list');
|
? (array)$data['segments']
|
||||||
} else {
|
: array()
|
||||||
$segments = Segment::whereIn('id', (array)$data['segments'])->findMany();
|
);
|
||||||
|
|
||||||
if(empty($segments)) {
|
|
||||||
$errors[] = __('You need to select a list');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($data['segments']);
|
unset($data['segments']);
|
||||||
|
|
||||||
$subscriber = false;
|
if(empty($segment_ids)) {
|
||||||
|
$errors[] = __('You need to select a list');
|
||||||
|
}
|
||||||
|
|
||||||
if(!empty($errors)) {
|
if(!empty($errors)) {
|
||||||
wp_send_json(array('errors' => $errors));
|
wp_send_json(array('errors' => $errors));
|
||||||
} else {
|
|
||||||
if(!empty($data['email'])) {
|
|
||||||
$subscriber = Subscriber::where('email', $data['email'])->findOne();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$signup_confirmation = Setting::getValue('signup_confirmation', array());
|
$subscriber = Subscriber::subscribe($data, $segment_ids);
|
||||||
|
|
||||||
if($subscriber === false) {
|
|
||||||
// create new subscriber
|
|
||||||
$data['status'] = (
|
|
||||||
(!empty($signup_confirmation['enabled']))
|
|
||||||
? 'unconfirmed' : 'subscribed'
|
|
||||||
);
|
|
||||||
|
|
||||||
// custom fields
|
|
||||||
$custom_fields = array();
|
|
||||||
foreach($data as $key => $value) {
|
|
||||||
if(strpos($key, 'cf_') === 0) {
|
|
||||||
$custom_fields[substr($key, 3)] = $value;
|
|
||||||
unset($data[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// insert new subscriber
|
|
||||||
$subscriber = Subscriber::createOrUpdate($data);
|
|
||||||
|
|
||||||
if($subscriber === false || !$subscriber->id()) {
|
if($subscriber === false || !$subscriber->id()) {
|
||||||
$errors = array_merge($errors, $subscriber->getValidationErrors());
|
$errors = array_merge($errors, $subscriber->getValidationErrors());
|
||||||
} else {
|
|
||||||
// add custom fields
|
|
||||||
if(!empty($custom_fields)) {
|
|
||||||
foreach($custom_fields as $custom_field_id => $value) {
|
|
||||||
if(is_array($value)) {
|
|
||||||
// date
|
|
||||||
$value = mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
|
|
||||||
}
|
}
|
||||||
$subscriber_custom_field = SubscriberCustomField::create();
|
|
||||||
$subscriber_custom_field->hydrate(array(
|
if(!empty($errors)) {
|
||||||
'subscriber_id' => $subscriber->id(),
|
wp_send_json(array(
|
||||||
'custom_field_id' => $custom_field_id,
|
'result' => false,
|
||||||
'value' => $value
|
'errors' => $errors
|
||||||
));
|
));
|
||||||
$subscriber_custom_field->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$subscriber->set('status', (
|
|
||||||
!empty($signup_confirmation['enabled'])
|
|
||||||
? 'unconfirmed' : 'subscribed'
|
|
||||||
));
|
|
||||||
|
|
||||||
// restore deleted subscriber
|
|
||||||
if($subscriber->deleted_at !== NULL) {
|
|
||||||
$subscriber->setExpr('deleted_at', 'NULL');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$subscriber->save()) {
|
|
||||||
$errors[] = __('An error occurred. Please try again later.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get segments
|
|
||||||
// IDEA: $subscriptions->addToSegments($data['segments']);
|
|
||||||
$segments_subscribed = array();
|
|
||||||
foreach($segments as $segment) {
|
|
||||||
if($segment->addSubscriber($subscriber->id())) {
|
|
||||||
$segments_subscribed[] = $segment->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if signup confirmation is enabled and the subscriber is unconfirmed
|
|
||||||
if(!empty($signup_confirmation['enabled'])
|
|
||||||
&& !empty($segments_subscribed)
|
|
||||||
&& $subscriber->status !== 'subscribed'
|
|
||||||
) {
|
|
||||||
// TODO: send confirmation email
|
|
||||||
// resend confirmation email
|
|
||||||
$is_sent = true;
|
|
||||||
/*$is_sent = static::sendSignupConfirmation(
|
|
||||||
$subscriber->asArray(),
|
|
||||||
$segments->asArray()
|
|
||||||
);*/
|
|
||||||
|
|
||||||
// error message if the email could not be sent
|
|
||||||
if($is_sent === false) {
|
|
||||||
$errors[] = __('The signup confirmation email could not be sent. Please check your settings.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get success message to display after subscription
|
// get success message to display after subscription
|
||||||
@@ -223,15 +135,6 @@ class Subscribers {
|
|||||||
? unserialize($form->settings) : null
|
? unserialize($form->settings) : null
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!empty($errors)) {
|
|
||||||
wp_send_json(array(
|
|
||||||
'result' => false,
|
|
||||||
'errors' => $errors
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($form_settings !== null) {
|
if($form_settings !== null) {
|
||||||
$message = $form_settings['success_message'];
|
$message = $form_settings['success_message'];
|
||||||
|
|
||||||
@@ -274,7 +177,7 @@ class Subscribers {
|
|||||||
// response depending on context
|
// response depending on context
|
||||||
if($doing_ajax === true) {
|
if($doing_ajax === true) {
|
||||||
wp_send_json(array(
|
wp_send_json(array(
|
||||||
'result' => $result,
|
'result' => true,
|
||||||
'message' => $message
|
'message' => $message
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
@@ -104,15 +104,15 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<select
|
<select
|
||||||
id="mailpoet_subscribe_on_comment_lists"
|
id="mailpoet_subscribe_on_comment_segments"
|
||||||
name="subscribe[on_comment][lists][]"
|
name="subscribe[on_comment][segments][]"
|
||||||
placeholder="<%= __('Choose a list') %>"
|
placeholder="<%= __('Choose a list') %>"
|
||||||
multiple
|
multiple
|
||||||
>
|
>
|
||||||
<% for segment in segments %>
|
<% for segment in segments %>
|
||||||
<option
|
<option
|
||||||
value="<%= segment.id %>"
|
value="<%= segment.id %>"
|
||||||
<% if(segment.id in settings.subscribe.on_comment.lists) %>
|
<% if(segment.id in settings.subscribe.on_comment.segments) %>
|
||||||
selected="selected"
|
selected="selected"
|
||||||
<% endif %>
|
<% endif %>
|
||||||
><%= segment.name %></option>
|
><%= segment.name %></option>
|
||||||
@@ -165,15 +165,15 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<select
|
<select
|
||||||
id="mailpoet_subscribe_on_register_lists"
|
id="mailpoet_subscribe_on_register_segments"
|
||||||
name="subscribe[on_register][lists][]"
|
name="subscribe[on_register][segments][]"
|
||||||
placeholder="<%= __('Choose a list') %>"
|
placeholder="<%= __('Choose a list') %>"
|
||||||
multiple
|
multiple
|
||||||
>
|
>
|
||||||
<% for segment in segments %>
|
<% for segment in segments %>
|
||||||
<option
|
<option
|
||||||
value="<%= segment.id %>"
|
value="<%= segment.id %>"
|
||||||
<% if(segment.id in settings.subscribe.on_register.lists) %>
|
<% if(segment.id in settings.subscribe.on_register.segments) %>
|
||||||
selected="selected"
|
selected="selected"
|
||||||
<% endif %>
|
<% endif %>
|
||||||
><%= segment.name %></option>
|
><%= segment.name %></option>
|
||||||
@@ -231,15 +231,15 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<select
|
<select
|
||||||
id="mailpoet_subscription_edit_lists"
|
id="mailpoet_subscription_edit_segments"
|
||||||
name="subscription[lists][]"
|
name="subscription[segments][]"
|
||||||
placeholder="<%= __('Leave empty to show all lists') %>"
|
placeholder="<%= __('Leave empty to show all lists') %>"
|
||||||
multiple
|
multiple
|
||||||
>
|
>
|
||||||
<% for segment in segments %>
|
<% for segment in segments %>
|
||||||
<option
|
<option
|
||||||
value="<%= segment.id %>"
|
value="<%= segment.id %>"
|
||||||
<% if(segment.id in settings.subscription.lists) %>
|
<% if(segment.id in settings.subscription.segments) %>
|
||||||
selected="selected"
|
selected="selected"
|
||||||
<% endif %>
|
<% endif %>
|
||||||
><%= segment.name %></option>
|
><%= segment.name %></option>
|
||||||
@@ -307,7 +307,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<select
|
<select
|
||||||
id="mailpoet_shortcode_subscribers_list"
|
id="mailpoet_shortcode_subscribers_count"
|
||||||
data-shortcode="mailpoet_subscribers_count"
|
data-shortcode="mailpoet_subscribers_count"
|
||||||
data-output="mailpoet_shortcode_subscribers"
|
data-output="mailpoet_shortcode_subscribers"
|
||||||
placeholder="<%= __('Leave empty to show all lists') %>"
|
placeholder="<%= __('Leave empty to show all lists') %>"
|
||||||
@@ -328,25 +328,26 @@
|
|||||||
// on dom loaded
|
// on dom loaded
|
||||||
$(function() {
|
$(function() {
|
||||||
// select2 instances
|
// select2 instances
|
||||||
$('#mailpoet_subscribe_on_comment_lists').select2();
|
$('#mailpoet_subscribe_on_comment_segments').select2();
|
||||||
$('#mailpoet_subscribe_on_register_lists').select2();
|
$('#mailpoet_subscribe_on_register_segments').select2();
|
||||||
$('#mailpoet_subscription_edit_lists').select2();
|
$('#mailpoet_subscription_edit_segments').select2();
|
||||||
$('#mailpoet_shortcode_archives_list').select2();
|
$('#mailpoet_shortcode_archives_list').select2();
|
||||||
$('#mailpoet_shortcode_subscribers_list').select2();
|
$('#mailpoet_shortcode_subscribers_count').select2();
|
||||||
|
|
||||||
// shortcodes
|
// shortcodes
|
||||||
$('#mailpoet_shortcode_archives_list, #mailpoet_shortcode_subscribers_list')
|
$('#mailpoet_shortcode_archives_list, #mailpoet_shortcode_subscribers_count')
|
||||||
.on('change', function() {
|
.on('change', function() {
|
||||||
var shortcode = $(this).data('shortcode'),
|
var shortcode = $(this).data('shortcode'),
|
||||||
values = $(this).val() || [];
|
values = $(this).val() || [];
|
||||||
|
|
||||||
if(values.length > 0) {
|
if (values.length > 0) {
|
||||||
shortcode += ' list_id="';
|
shortcode += ' list_id="';
|
||||||
shortcode += values.join(',');
|
shortcode += values.join(',');
|
||||||
shortcode += '"';
|
shortcode += '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#' + $(this).data('output')).val('[' + shortcode + ']');
|
$('#' + $(this).data('output'))
|
||||||
|
.val('[' + shortcode + ']');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user