From 61ddc340c6fe6976049a519cee2397126b2b3bf1 Mon Sep 17 00:00:00 2001 From: champsupertramp Date: Sat, 2 Apr 2016 00:09:59 +0800 Subject: [PATCH] Add option to allow primary email editable in profile view --- core/um-actions-form.php | 4 +++- core/um-fields.php | 8 +++++++- um-config.php | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/um-actions-form.php b/core/um-actions-form.php index 7812b55d..e1f47115 100644 --- a/core/um-actions-form.php +++ b/core/um-actions-form.php @@ -358,7 +358,9 @@ if ( $args[$key] == '' && in_array( $key, array('user_email') ) ) { $ultimatemember->form->add_error($key, __('You must provide your email','ultimatemember') ); - } else if ( $mode == 'register' && email_exists( $args[$key] ) ) { + } else if ( in_array( $mode, array('register') ) && email_exists( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); + } else if ( in_array( $mode, array('profile') ) && email_exists( $args[$key] ) != $args['user_id'] ) { $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); } else if ( !is_email( $args[$key] ) ) { $ultimatemember->form->add_error($key, __('This is not a valid email','ultimatemember') ); diff --git a/core/um-fields.php b/core/um-fields.php index e1bca1af..e3e9663a 100644 --- a/core/um-fields.php +++ b/core/um-fields.php @@ -909,7 +909,13 @@ class UM_Fields { if ( !um_can_edit_field( $data ) ) return; // fields that need to be disabled in edit mode (profile) - if ( in_array( $key, array('user_email','username','user_login','user_password') ) && $this->editing == true && $this->set_mode == 'profile' ) { + $arr_restricted_fields = array('user_email','username','user_login','user_password'); + + if( um_get_option('editable_primary_email_in_profile') == 1 ){ + unset( $arr_restricted_fields[0] ); // remove user_email + } + + if ( in_array( $key, $arr_restricted_fields ) && $this->editing == true && $this->set_mode == 'profile' ) { return; } diff --git a/um-config.php b/um-config.php index 8e7169be..5e09c729 100644 --- a/um-config.php +++ b/um-config.php @@ -202,6 +202,16 @@ $this->sections[] = array( 'off' => __('Off','ultimatemember'), ), + array( + 'id' => 'editable_primary_email_in_profile', + 'type' => 'switch', + 'title' => __( 'Editable primary email field in profile view','ultimatemember' ), + 'default' => 0, + 'desc' => __('Allow users to edit their primary emails in profile view ( when email address field is added only )','ultimatemember'), + 'on' => __('On','ultimatemember'), + 'off' => __('Off','ultimatemember'), + ), + ) );