diff --git a/lib/Config/Hooks.php b/lib/Config/Hooks.php index 9d77f9762a..c9af19f6b0 100644 --- a/lib/Config/Hooks.php +++ b/lib/Config/Hooks.php @@ -81,6 +81,16 @@ class Hooks { ); } } + + // Manage subscription + add_action( + 'admin_post_mailpoet_subscription_update', + '\MailPoet\Subscription\Manage::onSave' + ); + add_action( + 'admin_post_nopriv_mailpoet_subscription_update', + '\MailPoet\Subscription\Manage::onSave' + ); } function setupWPUsers() { diff --git a/lib/Form/Block/Base.php b/lib/Form/Block/Base.php index d9cd6a893e..7adf3e1a2e 100644 --- a/lib/Form/Block/Base.php +++ b/lib/Form/Block/Base.php @@ -116,11 +116,11 @@ abstract class Base { protected static function getInputModifiers($block = array()) { $modifiers = array(); - if(isset($block['params']['readonly'])) { + if(isset($block['params']['readonly']) && $block['params']['readonly']) { $modifiers[] = 'readonly'; } - if(isset($block['params']['disabled'])) { + if(isset($block['params']['disabled']) && $block['params']['disabled']) { $modifiers[] = 'disabled'; } return join(' ', $modifiers); diff --git a/lib/Subscription/Manage.php b/lib/Subscription/Manage.php index fd690211f2..ffd310a13c 100644 --- a/lib/Subscription/Manage.php +++ b/lib/Subscription/Manage.php @@ -7,6 +7,7 @@ class Manage { static function onSave() { $action = (isset($_POST['action']) ? $_POST['action'] : null); + if($action !== 'mailpoet_subscription_update') { Url::redirectBack(); } diff --git a/lib/Subscription/Pages.php b/lib/Subscription/Pages.php index ebe2aebef8..e5111a4ecc 100644 --- a/lib/Subscription/Pages.php +++ b/lib/Subscription/Pages.php @@ -249,13 +249,15 @@ class Pages { ); }, $segments); + $fields = array( array( 'id' => 'first_name', 'type' => 'text', 'params' => array( 'label' => __('First name'), - 'value' => $subscriber->first_name + 'value' => $subscriber->first_name, + 'disabled' => ($subscriber->wp_user_id !== null) ) ), array( @@ -263,7 +265,8 @@ class Pages { 'type' => 'text', 'params' => array( 'label' => __('Last name'), - 'value' => $subscriber->last_name + 'value' => $subscriber->last_name, + 'disabled' => ($subscriber->wp_user_id !== null) ) ), array( @@ -329,12 +332,23 @@ class Pages { $form_html .= '

'; $form_html .= ''; $form_html .= '
'; + // special case for WP users as they cannot edit their subscriber's email if($subscriber->wp_user_id !== null) { - $form_html .= str_replace( - array('[link]', '[/link]'), - array('', ''), - __('[link]Log in to your account[/link] to update your email.') - ); + // check if subscriber's associated WP user is the currently logged in WP user + $wp_current_user = wp_get_current_user(); + if($wp_current_user->user_email === $subscriber->email) { + $form_html .= str_replace( + array('[link]', '[/link]'), + array('', ''), + __('[link]Edit your profile[/link] to update your email.') + ); + } else { + $form_html .= str_replace( + array('[link]', '[/link]'), + array('', ''), + __('[link]Log in to your account[/link] to update your email.') + ); + } } else { $form_html .= __('Need to change your email address? Unsubscribe here, then simply sign up again.'); }