edit profile rendering (missing segments list) + fallback for Url::redirectBack()
This commit is contained in:
@ -35,7 +35,7 @@ class Checkbox extends Base {
|
|||||||
|
|
||||||
$html .= $field_validation;
|
$html .= $field_validation;
|
||||||
|
|
||||||
$html .= ' /> '.$option['value'];
|
$html .= ' /> '.esc_attr($option['value']);
|
||||||
|
|
||||||
$html .= '</label>';
|
$html .= '</label>';
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class Radio extends Base {
|
|||||||
|
|
||||||
$html .= $field_validation;
|
$html .= $field_validation;
|
||||||
|
|
||||||
$html .= ' /> '.esc_attr($option['value']);
|
$html .= ' /> '.esc_attr($option['value']);
|
||||||
|
|
||||||
$html .= '</label>';
|
$html .= '</label>';
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class Segment extends Base {
|
|||||||
$html .= 'name="'.$field_name.'[]" ';
|
$html .= 'name="'.$field_name.'[]" ';
|
||||||
$html .= 'value="'.$option['id'].'" '.$is_checked.' ';
|
$html .= 'value="'.$option['id'].'" '.$is_checked.' ';
|
||||||
$html .= $field_validation;
|
$html .= $field_validation;
|
||||||
$html .= ' /> '.$option['name'];
|
$html .= ' /> '.esc_attr($option['name']);
|
||||||
$html .= '</label>';
|
$html .= '</label>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class Select extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$html .= '<option value="'.$value.'" '.$is_selected.'>';
|
$html .= '<option value="'.$value.'" '.$is_selected.'>';
|
||||||
$html .= $label;
|
$html .= esc_attr($label);
|
||||||
$html .= '</option>';
|
$html .= '</option>';
|
||||||
}
|
}
|
||||||
$html .= '</select>';
|
$html .= '</select>';
|
||||||
|
@ -10,6 +10,8 @@ use \MailPoet\Util\Helpers;
|
|||||||
use \MailPoet\Util\Url;
|
use \MailPoet\Util\Url;
|
||||||
|
|
||||||
class Pages {
|
class Pages {
|
||||||
|
const DEMO_EMAIL = 'demo@mailpoet.com';
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ class Pages {
|
|||||||
$subscriber = Subscriber::createOrUpdate($subscriber_data);
|
$subscriber = Subscriber::createOrUpdate($subscriber_data);
|
||||||
$errors = $subscriber->getErrors();
|
$errors = $subscriber->getErrors();
|
||||||
|
|
||||||
// TODO: success/error messages
|
// TBD: success/error messages (not present in MP2)
|
||||||
|
|
||||||
Url::redirectBack();
|
Url::redirectBack();
|
||||||
}
|
}
|
||||||
@ -127,7 +129,7 @@ class Pages {
|
|||||||
if($this->isPreview()) {
|
if($this->isPreview()) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
__('Edit your subscriber profile: %s'),
|
__('Edit your subscriber profile: %s'),
|
||||||
'demo@mailpoet.com'
|
self::DEMO_EMAIL
|
||||||
);
|
);
|
||||||
} else if($subscriber !== false) {
|
} else if($subscriber !== false) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
@ -154,7 +156,7 @@ class Pages {
|
|||||||
if($this->isPreview()) {
|
if($this->isPreview()) {
|
||||||
$subscriber = Subscriber::create();
|
$subscriber = Subscriber::create();
|
||||||
$subscriber->hydrate(array(
|
$subscriber->hydrate(array(
|
||||||
'email' => 'demo@mailpoet.com'
|
'email' => self::DEMO_EMAIL
|
||||||
));
|
));
|
||||||
} else if($subscriber !== false) {
|
} else if($subscriber !== false) {
|
||||||
$subscriber = $subscriber
|
$subscriber = $subscriber
|
||||||
@ -180,7 +182,6 @@ class Pages {
|
|||||||
$segments = Segment::getPublic()
|
$segments = Segment::getPublic()
|
||||||
->findMany();
|
->findMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
$subscribed_segment_ids = array();
|
$subscribed_segment_ids = array();
|
||||||
if(!empty($subscriber->subscriptions)) {
|
if(!empty($subscriber->subscriptions)) {
|
||||||
foreach ($subscriber->subscriptions as $subscription) {
|
foreach ($subscriber->subscriptions as $subscription) {
|
||||||
@ -263,20 +264,31 @@ class Pages {
|
|||||||
$fields,
|
$fields,
|
||||||
$custom_fields,
|
$custom_fields,
|
||||||
array(
|
array(
|
||||||
|
array(
|
||||||
|
'id' => 'segments',
|
||||||
|
'type' => 'segment',
|
||||||
|
'params' => array(
|
||||||
|
'label' => __('Your lists'),
|
||||||
|
'values' => $segments
|
||||||
|
)
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'id' => 'submit',
|
'id' => 'submit',
|
||||||
'type' => 'submit',
|
'type' => 'submit',
|
||||||
'params' => array(
|
'params' => array(
|
||||||
'label' => __('Subscribe!')
|
'label' => __('Save')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$form_html = '<form method="POST" action="'.admin_url('admin-post.php').'" novalidate>';
|
$form_html = '<form method="POST" '.
|
||||||
|
'action="'.admin_url('admin-post.php').'" '.
|
||||||
|
'novalidate>';
|
||||||
$form_html .= '<input type="hidden" name="action" value="update" />';
|
$form_html .= '<input type="hidden" name="action" value="update" />';
|
||||||
$form_html .= '<input type="hidden" name="mailpoet_redirect" value="'.Url::getCurrentUrl().'" />';
|
$form_html .= '<input type="hidden" name="segments" value="" />';
|
||||||
|
$form_html .= '<input type="hidden" name="mailpoet_redirect" '.
|
||||||
|
'value="'.Url::getCurrentUrl().'" />';
|
||||||
$form_html .= \MailPoet\Form\Renderer::renderBlocks($form);
|
$form_html .= \MailPoet\Form\Renderer::renderBlocks($form);
|
||||||
$form_html .= '</form>';
|
$form_html .= '</form>';
|
||||||
return $form_html;
|
return $form_html;
|
||||||
|
@ -21,17 +21,24 @@ class Url {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static function redirectBack() {
|
static function redirectBack() {
|
||||||
$referer = (isset($_REQUEST['mailpoet_redirect'])
|
// check mailpoet_redirect parameter
|
||||||
? $_REQUEST['mailpoet_redirect']
|
$referer = (isset($_POST['mailpoet_redirect'])
|
||||||
|
? $_POST['mailpoet_redirect']
|
||||||
: null
|
: null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// fallback: http referer
|
||||||
if($referer === null) {
|
if($referer === null) {
|
||||||
// try to get the server's referer
|
|
||||||
if(!empty($_SERVER['HTTP_REFERER'])) {
|
if(!empty($_SERVER['HTTP_REFERER'])) {
|
||||||
$referer = $_SERVER['HTTP_REFERER'];
|
$referer = $_SERVER['HTTP_REFERER'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fallback: home_url
|
||||||
|
if($referer === null) {
|
||||||
|
$referer = home_url();
|
||||||
|
}
|
||||||
|
|
||||||
if($referer !== null) {
|
if($referer !== null) {
|
||||||
self::redirectTo($referer);
|
self::redirectTo($referer);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user