fixed list selection widget + started form submission
This commit is contained in:
@ -22,8 +22,8 @@ class Segment extends Base {
|
||||
|
||||
$html .= '<label class="mailpoet_checkbox_label">';
|
||||
$html .= '<input type="checkbox" class="mailpoet_checkbox" ';
|
||||
$html .= 'name="'.$field_name.'" ';
|
||||
$html .= 'value="'.$segment['id'].'" '.$is_checked;
|
||||
$html .= 'name="'.$field_name.'[]" ';
|
||||
$html .= 'value="'.$segment['id'].'" '.$is_checked.' ';
|
||||
$html .= $field_validation;
|
||||
$html .= ' />'.$segment['name'];
|
||||
$html .= '</label>';
|
||||
|
@ -32,11 +32,16 @@ class Styles {
|
||||
.mailpoet_textarea,
|
||||
.mailpoet_select,
|
||||
.mailpoet_radio,
|
||||
.mailpoet_checkbox,
|
||||
.mailpoet_date {
|
||||
display:block;
|
||||
}
|
||||
|
||||
.mailpoet_checkbox {
|
||||
display:inline;
|
||||
margin-right: 5px;
|
||||
vertical-align:middle;
|
||||
}
|
||||
|
||||
.mailpoet_validate_success {
|
||||
color:#468847;
|
||||
}
|
||||
|
@ -2,14 +2,31 @@
|
||||
namespace MailPoet\Form;
|
||||
use \MailPoet\Config\Renderer;
|
||||
use \MailPoet\Models\Form;
|
||||
use \MailPoet\Models\Segment;
|
||||
use \MailPoet\Models\Setting;
|
||||
use \MailPoet\Models\Subscriber;
|
||||
use \MailPoet\Form\Renderer as FormRenderer;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Widget extends \WP_Widget {
|
||||
|
||||
function __construct () {
|
||||
add_action(
|
||||
'wp_ajax_mailpoet_form_subscribe',
|
||||
array($this, 'subscribe')
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_nopriv_mailpoet_form_subscribe',
|
||||
array($this, 'subscribe')
|
||||
);
|
||||
add_action(
|
||||
'admin_post_nopriv_mailpoet_form_subscribe',
|
||||
array($this, 'subscribe')
|
||||
);
|
||||
add_action(
|
||||
'admin_post_mailpoet_form_subscribe',
|
||||
array($this, 'subscribe')
|
||||
);
|
||||
return parent::__construct(
|
||||
'mailpoet_form',
|
||||
__("MailPoet Subscription Form"),
|
||||
@ -173,6 +190,249 @@ class Widget extends \WP_Widget {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function subscribe() {
|
||||
// check to see if we're in an ajax request or post request
|
||||
$doing_ajax = (bool)(defined('DOING_AJAX') && DOING_AJAX);
|
||||
|
||||
if(isset($_GET['action']) && $_GET['action'] === 'mailpoet_form_subscribe') {
|
||||
// input data
|
||||
$data = array();
|
||||
|
||||
// output errors
|
||||
$errors = array();
|
||||
|
||||
// get posted data
|
||||
// ajax data
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
// -or- post data
|
||||
if($data === NULL && !empty($_POST)) { $data = $_POST; }
|
||||
|
||||
// create or update subscriber
|
||||
$subscriber = Subscriber::where('email', $data['email'])->findOne();
|
||||
|
||||
// is signup confirmation enabled?
|
||||
$signup_confirmation = Setting::getValue('signup_confirmation');
|
||||
if($subscriber === false) {
|
||||
// create new subscriber
|
||||
$data['status'] = (
|
||||
($signup_confirmation['enabled'] === true)
|
||||
? 'unconfirmed' : 'subscribed'
|
||||
);
|
||||
|
||||
// // set custom fields
|
||||
// $meta_fields = $mailpoet->getOption('mailpoet_subscriber_meta', array());
|
||||
// if(!empty($meta_fields)) {
|
||||
// // loop through data to see if any meta field has been passed
|
||||
// foreach($meta_fields as $field => $field_data) {
|
||||
// // check if it's a mandatory field
|
||||
// $is_required = (isset($field_data['params']['required']) && (bool)$field_data['params']['required'] === true);
|
||||
|
||||
// if(array_key_exists($field, $data)) {
|
||||
// // check if it's a mandatory field
|
||||
// if($is_required === true && empty($data[$field])) {
|
||||
// // if it's missing, throw an error
|
||||
// $errors[] = sprintf(__('"%s" is required'), $field_data['name']);
|
||||
// } else {
|
||||
// // assign field to subscriber
|
||||
// $subscriber[$field] = $data[$field];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if(empty($errors)) {
|
||||
// insert new subscriber
|
||||
$subscriber = Subscriber::createOrUpdate($data);
|
||||
if($subscriber === false || !$subscriber->id()) {
|
||||
$errors = array_merge($errors, $subscriber->getValidationErrors());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// restore deleted subscriber
|
||||
if($subscriber->deleted_at !== NULL) {
|
||||
// reset subscriber state (depends whether signup confirmation is enabled)
|
||||
$subscriber
|
||||
->set('status', array(
|
||||
($signup_confirmation['enabled'] === true)
|
||||
? 'unconfirmed' : 'subscribed'
|
||||
))
|
||||
->setExpr('deleted_at', 'NULL');
|
||||
|
||||
|
||||
if(!$subscriber->save()) {
|
||||
$errors[] = __('An error occurred. Please try again later.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if form id has been passed
|
||||
if(isset($data['form']) && (int)$data['form'] > 0) {
|
||||
// get form id
|
||||
$form_id = (int)$data['form'];
|
||||
// get form
|
||||
$form = Form::findOne($form_id);
|
||||
|
||||
if($form === false || !$form->id()) {
|
||||
$errors[] = __('This form does not exist. Please check your forms.');
|
||||
} else {
|
||||
// set subscriptions
|
||||
if(empty($data['segments'])) {
|
||||
$errors[] = __('You need to select a list');
|
||||
} else {
|
||||
// get segments
|
||||
$segments = Segment::whereIn('id', $data['segments'])->findMany();
|
||||
$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($signup_confirmation['enabled'] === true
|
||||
&& !empty($segments_subscribed)
|
||||
&& $subscriber->status !== 'subscribed'
|
||||
) {
|
||||
// TODO: send confirmation email
|
||||
// resend confirmation email
|
||||
$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
|
||||
$form_settings = (
|
||||
isset($form->settings)
|
||||
? unserialize($form->settings) : null
|
||||
);
|
||||
|
||||
if($subscriber !== null && empty($errors)) {
|
||||
$success = true;
|
||||
$message = $form_settings['success_message'];
|
||||
} else {
|
||||
$success = false;
|
||||
$message = join('<br />', $errors);
|
||||
}
|
||||
|
||||
if($form_settings !== null) {
|
||||
|
||||
// url params for non ajax requests
|
||||
if($doing_ajax === false) {
|
||||
// get referer
|
||||
$referer = (wp_get_referer() !== false) ? wp_get_referer() : $_SERVER['HTTP_REFERER'];
|
||||
|
||||
// redirection parameters
|
||||
$params = array(
|
||||
'mailpoet_form' => (int)$data['form']
|
||||
);
|
||||
|
||||
// handle success/error messages
|
||||
if($success === false) {
|
||||
$params['mailpoet_error'] = urlencode($message);
|
||||
} else {
|
||||
$params['mailpoet_success'] = urlencode($message);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($form_settings['on_success']) {
|
||||
case 'page':
|
||||
// response depending on context
|
||||
if($doing_ajax === true) {
|
||||
echo json_encode(array(
|
||||
'success' => $success,
|
||||
'page' => get_permalink($form_settings['success_page']),
|
||||
'message' => $message
|
||||
));
|
||||
} else {
|
||||
$redirect_to = ($success === false) ? $referer : get_permalink($form_settings['success_page']);
|
||||
wp_redirect(add_query_arg($params, $redirect_to));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'message':
|
||||
default:
|
||||
// response depending on context
|
||||
if($doing_ajax === true) {
|
||||
echo json_encode(array(
|
||||
'success' => $success,
|
||||
'message' => $message
|
||||
));
|
||||
} else {
|
||||
// redirect to previous page
|
||||
wp_redirect(add_query_arg($params, $referer));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
static function sendSignupConfirmation(array $subscriber, array $segments) {
|
||||
print "<pre>";
|
||||
print_r($subscriber);
|
||||
print_r($segments);
|
||||
print "</pre>";
|
||||
//$mailer = new MailPoetMailer($mailpoet->settings()->getAll());
|
||||
$signup_confirmation = Setting::getValue('signup_confirmation');
|
||||
|
||||
$body = (
|
||||
!empty($signup_confirmation['body'])
|
||||
? $signup_confirmation['body'] : ''
|
||||
);
|
||||
|
||||
// check for lists_to_confirm tag
|
||||
if(strpos($body, '[lists_to_confirm]') !== FALSE) {
|
||||
// gather all names from lists
|
||||
$segment_names = array_map(function($segment) { return $segment['list_name']; }, $segments);
|
||||
// replace shortcode by list names in email's body
|
||||
$body = str_replace('[lists_to_confirm]', join(', ', $segment_names), $body);
|
||||
}
|
||||
|
||||
// check for activation_link tags
|
||||
if(strpos($body, '[activation_link]') !== FALSE && strpos($body, '[/activation_link]') !== FALSE) {
|
||||
// get confirmation page id
|
||||
$confirmation_page_id = $mailpoet->settings()->get('signup_confirmation_page');
|
||||
|
||||
// generate confirmation link
|
||||
$confirmation_link = add_query_arg(array(
|
||||
'mailpoet_key' => $subscriber['subscriber_digest']
|
||||
), get_permalink($confirmation_page_id));
|
||||
|
||||
// we have both tags
|
||||
$body = str_replace(
|
||||
array('[activation_link]', '[/activation_link]'),
|
||||
array('<a href="'.$confirmation_link.'">', '</a>'),
|
||||
$body
|
||||
);
|
||||
} else {
|
||||
// no activation link tags detected
|
||||
// TODO...
|
||||
}
|
||||
|
||||
// send confirmation email
|
||||
return $mailer->send(array(
|
||||
'from_email' => $mailpoet->settings()->get('signup_confirmation_from_email'),
|
||||
'from_name' => $mailpoet->settings()->get('signup_confirmation_from_name'),
|
||||
'reply_email' => $mailpoet->settings()->get('signup_confirmation_reply_email'),
|
||||
'reply_name' => $mailpoet->settings()->get('signup_confirmation_reply_name'),
|
||||
'subject' => $signup_confirmation['subject'],
|
||||
'html' => nl2br($signup_confirmation['body']),
|
||||
// 'text' => '',
|
||||
'to_email' => $subscriber['subscriber_email'],
|
||||
'to_name' => $subscriber['subscriber_email'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// mailpoet shortcodes
|
||||
@ -194,27 +454,23 @@ function mailpoet_form_shortcode($params = array()) {
|
||||
}
|
||||
|
||||
/*
|
||||
add_action('wp_ajax_mailpoet_form_subscribe', 'mailpoet_form_subscribe');
|
||||
add_action('wp_ajax_nopriv_mailpoet_form_subscribe', 'mailpoet_form_subscribe');
|
||||
add_action('admin_post_nopriv_mailpoet_form_subscribe', 'mailpoet_form_subscribe');
|
||||
add_action('admin_post_mailpoet_form_subscribe', 'mailpoet_form_subscribe');
|
||||
add_action('init', 'mailpoet_form_subscribe');
|
||||
|
||||
add_action(
|
||||
'init',
|
||||
array(__NAMESPACE__.'\Widget', 'subscribe')
|
||||
);
|
||||
*/
|
||||
|
||||
// set the content filter to replace the shortcode
|
||||
|
||||
if(isset($_GET['mailpoet_page']) && strlen(trim($_GET['mailpoet_page'])) > 0) {
|
||||
$mailpoet = new MailPoetWPI();
|
||||
|
||||
switch($_GET['mailpoet_page']) {
|
||||
|
||||
case 'mailpoet_form_iframe':
|
||||
$form_id = (isset($_GET['mailpoet_form']) && (int)$_GET['mailpoet_form'] > 0) ? (int)$_GET['mailpoet_form'] : null;
|
||||
$form = $mailpoet->forms()->fetchById($form_id);
|
||||
$id = (isset($_GET['mailpoet_form']) && (int)$_GET['mailpoet_form'] > 0) ? (int)$_GET['mailpoet_form'] : null;
|
||||
$form = Form::findOne($id);
|
||||
|
||||
if($form !== null) {
|
||||
if($form !== false) {
|
||||
// render form
|
||||
print FormRenderer::getExport('html', $form);
|
||||
print FormRenderer::getExport('html', $form->asArray());
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
@ -228,9 +484,9 @@ if(isset($_GET['mailpoet_page']) && strlen(trim($_GET['mailpoet_page'])) > 0) {
|
||||
}
|
||||
|
||||
function mailpoet_page_title($title = '', $id = null) {
|
||||
$mailpoet = new MailPoetWPI();
|
||||
// get signup confirmation page id
|
||||
$page_id = $mailpoet->settings()->get('signup_confirmation_page');
|
||||
$signup_confirmation = Setting::getValue('signup_confirmation');
|
||||
$page_id = $signup_confirmation['page'];
|
||||
|
||||
// check if we're on the signup confirmation page
|
||||
if((int)$page_id === (int)$id) {
|
||||
@ -292,272 +548,4 @@ function mailpoet_page_content($content = '') {
|
||||
$content = str_replace('[mailpoet_page]', '', $content);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
function mailpoet_signup_confirmation_email(array $subscriber, array $lists) {
|
||||
$mailpoet = new MailPoetWPI();
|
||||
|
||||
$mailer = new MailPoetMailer($mailpoet->settings()->getAll());
|
||||
|
||||
// email subject & body
|
||||
$email_subject = $mailpoet->settings()->get('signup_confirmation_email_subject');
|
||||
$email_body = nl2br($mailpoet->settings()->get('signup_confirmation_email_body'));
|
||||
|
||||
// check for lists_to_confirm tag
|
||||
if(strpos($email_body, '[lists_to_confirm]') !== FALSE) {
|
||||
// gather all names from lists
|
||||
$list_names = array_map(function($list) { return $list['list_name']; }, $lists);
|
||||
// replace shortcode by list names in email's body
|
||||
$email_body = str_replace('[lists_to_confirm]', join(', ', $list_names), $email_body);
|
||||
}
|
||||
|
||||
// check for activation_link tags
|
||||
if(strpos($email_body, '[activation_link]') !== FALSE && strpos($email_body, '[/activation_link]') !== FALSE) {
|
||||
// get confirmation page id
|
||||
$confirmation_page_id = $mailpoet->settings()->get('signup_confirmation_page');
|
||||
|
||||
// generate confirmation link
|
||||
$confirmation_link = add_query_arg(array(
|
||||
'mailpoet_key' => $subscriber['subscriber_digest']
|
||||
), get_permalink($confirmation_page_id));
|
||||
|
||||
// we have both tags
|
||||
$email_body = str_replace(
|
||||
array('[activation_link]', '[/activation_link]'),
|
||||
array('<a href="'.$confirmation_link.'">', '</a>'),
|
||||
$email_body
|
||||
);
|
||||
} else {
|
||||
// no activation link tags detected
|
||||
// TODO...
|
||||
}
|
||||
|
||||
// send confirmation email
|
||||
return $mailer->send(array(
|
||||
'from_email' => $mailpoet->settings()->get('signup_confirmation_from_email'),
|
||||
'from_name' => $mailpoet->settings()->get('signup_confirmation_from_name'),
|
||||
'reply_email' => $mailpoet->settings()->get('signup_confirmation_reply_email'),
|
||||
'reply_name' => $mailpoet->settings()->get('signup_confirmation_reply_name'),
|
||||
'subject' => $email_subject,
|
||||
'html' => $email_body,
|
||||
'text' => '',
|
||||
'to_email' => $subscriber['subscriber_email'],
|
||||
'to_name' => $subscriber['subscriber_email'],
|
||||
));
|
||||
}
|
||||
|
||||
function mailpoet_form_subscribe() {
|
||||
// check to see if we're in an ajax request or post request
|
||||
$doing_ajax = (bool)(defined('DOING_AJAX') && DOING_AJAX);
|
||||
|
||||
if(isset($_GET['action']) && $_GET['action'] === 'mailpoet_form_subscribe') {
|
||||
|
||||
// MailPoetWPI instance
|
||||
$mailpoet = new MailPoetWPI();
|
||||
|
||||
// input data
|
||||
$data = array();
|
||||
|
||||
// output errors
|
||||
$errors = array();
|
||||
|
||||
// get posted data
|
||||
// ajax data
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
// -or- post data
|
||||
if($data === NULL && !empty($_POST)) { $data = $_POST; }
|
||||
|
||||
// define null subscriber
|
||||
$subscriber = null;
|
||||
|
||||
// check if email is valid
|
||||
if(MailPoetMailer::isEmailAddress($data['email']) === false) {
|
||||
// email invalid
|
||||
$errors[] = __('Invalid email address.');
|
||||
} else {
|
||||
// search for subscriber in database
|
||||
$subscribers = $mailpoet->subscribers()->select(array(
|
||||
'filter' => array(
|
||||
'subscriber_email' => $data['email']
|
||||
),
|
||||
'offset' => 0,
|
||||
'limit' => 1
|
||||
));
|
||||
|
||||
// check if we have any subscriber that matches
|
||||
if(count($subscribers) > 0) {
|
||||
// use existing subscriber
|
||||
$subscriber = $subscribers[0];
|
||||
}
|
||||
|
||||
// is signup confirmation enabled?
|
||||
$needs_confirmation = (bool)$mailpoet->settings()->get('signup_confirmation');
|
||||
|
||||
if($subscriber === null) {
|
||||
// create new subscriber
|
||||
$subscriber = array(
|
||||
'subscriber_email' => $data['email'],
|
||||
'subscriber_firstname' => (isset($data['subscriber_firstname'])) ? $data['subscriber_firstname'] : '',
|
||||
'subscriber_lastname' => (isset($data['subscriber_lastname'])) ? $data['subscriber_lastname'] : '',
|
||||
'subscriber_state' => ($needs_confirmation === true) ? MailPoetSubscribers::STATE_UNCONFIRMED : MailPoetSubscribers::STATE_SUBSCRIBED,
|
||||
'subscriber_created_at' => time()
|
||||
);
|
||||
|
||||
// set custom fields
|
||||
$meta_fields = $mailpoet->getOption('mailpoet_subscriber_meta', array());
|
||||
if(!empty($meta_fields)) {
|
||||
// loop through data to see if any meta field has been passed
|
||||
foreach($meta_fields as $field => $field_data) {
|
||||
// check if it's a mandatory field
|
||||
$is_required = (isset($field_data['params']['required']) && (bool)$field_data['params']['required'] === true);
|
||||
|
||||
if(array_key_exists($field, $data)) {
|
||||
// check if it's a mandatory field
|
||||
if($is_required === true && empty($data[$field])) {
|
||||
// if it's missing, throw an error
|
||||
$errors[] = sprintf(__('"%s" is required'), $field_data['name']);
|
||||
} else {
|
||||
// assign field to subscriber
|
||||
$subscriber[$field] = $data[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($errors)) {
|
||||
// insert new subscriber
|
||||
try {
|
||||
$subscriber = $mailpoet->subscribers()->insert($subscriber);
|
||||
} catch(Exception $e) {
|
||||
$errors[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// restore deleted subscriber
|
||||
if($subscriber['subscriber_deleted_at'] !== NULL) {
|
||||
// reset subscriber state (depends whether signup confirmation is enabled)
|
||||
if($needs_confirmation === true) {
|
||||
$subscriber['subscriber_state'] = MailPoetSubscribers::STATE_UNCONFIRMED;
|
||||
} else {
|
||||
$subscriber['subscriber_state'] = MailPoetSubscribers::STATE_SUBSCRIBED;
|
||||
}
|
||||
try {
|
||||
// update subscriber (reset deleted_at and state)
|
||||
$mailpoet->subscribers()->update(array(
|
||||
'subscriber' => $subscriber['subscriber'],
|
||||
'subscriber_state' => $subscriber['subscriber_state'],
|
||||
'subscriber_deleted_at' => NULL
|
||||
));
|
||||
} catch(Exception $e) {
|
||||
$errors[] = __('An error occurred. Please try again later.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if form id has been passed
|
||||
if(isset($data['form']) && (int)$data['form'] > 0) {
|
||||
// get form id
|
||||
$form_id = (int)$data['form'];
|
||||
// get form
|
||||
$form = $mailpoet->forms()->fetchById($form_id);
|
||||
|
||||
if($form === null) {
|
||||
$errors[] = __('This form does not exist. Please check your forms.');
|
||||
} else {
|
||||
// set subscriptions
|
||||
if(empty($data['lists'])) {
|
||||
$errors[] = __('You need to select a list');
|
||||
} else {
|
||||
// extract list ids
|
||||
$list_ids = array_map('intval', explode(',', $data['lists']));
|
||||
// get lists
|
||||
$lists = $mailpoet->lists()->fetchByIds($list_ids);
|
||||
|
||||
// subscribe user to lists
|
||||
$has_subscribed = $mailpoet->subscriptions()->addSubscriberToLists($subscriber, $lists, $form);
|
||||
|
||||
// if signup confirmation is enabled and the subscriber is unconfirmed
|
||||
if( $needs_confirmation === true
|
||||
&& $has_subscribed === true
|
||||
&& !empty($lists)
|
||||
&& !empty($subscriber['subscriber_digest'])
|
||||
&& $subscriber['subscriber_state'] !== MailPoetSubscribers::STATE_SUBSCRIBED
|
||||
) {
|
||||
// resend confirmation email
|
||||
$is_sent = mailpoet_signup_confirmation_email($subscriber, $lists);
|
||||
|
||||
// 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
|
||||
$form_settings = (isset($form['settings']) ? $form['settings'] : null);
|
||||
|
||||
if($subscriber !== null && empty($errors)) {
|
||||
$success = true;
|
||||
$message = $form_settings['success_message'];
|
||||
} else {
|
||||
$success = false;
|
||||
$message = join('<br />', $errors);
|
||||
}
|
||||
|
||||
if($form_settings !== null) {
|
||||
|
||||
// url params for non ajax requests
|
||||
if($doing_ajax === false) {
|
||||
// get referer
|
||||
$referer = (wp_get_referer() !== false) ? wp_get_referer() : $_SERVER['HTTP_REFERER'];
|
||||
|
||||
// redirection parameters
|
||||
$params = array(
|
||||
'mailpoet_form' => (int)$data['form']
|
||||
);
|
||||
|
||||
// handle success/error messages
|
||||
if($success === false) {
|
||||
$params['mailpoet_error'] = urlencode($message);
|
||||
} else {
|
||||
$params['mailpoet_success'] = urlencode($message);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($form_settings['on_success']) {
|
||||
case 'page':
|
||||
// response depending on context
|
||||
if($doing_ajax === true) {
|
||||
echo json_encode(array(
|
||||
'success' => $success,
|
||||
'page' => get_permalink($form_settings['success_page']),
|
||||
'message' => $message
|
||||
));
|
||||
} else {
|
||||
$redirect_to = ($success === false) ? $referer : get_permalink($form_settings['success_page']);
|
||||
wp_redirect(add_query_arg($params, $redirect_to));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'message':
|
||||
default:
|
||||
// response depending on context
|
||||
if($doing_ajax === true) {
|
||||
echo json_encode(array(
|
||||
'success' => $success,
|
||||
'message' => $message
|
||||
));
|
||||
} else {
|
||||
// redirect to previous page
|
||||
wp_redirect(add_query_arg($params, $referer));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
exit();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
Reference in New Issue
Block a user