diff --git a/admin/core/um-admin-actions.php b/admin/core/um-admin-actions.php index b2815ba0..d89650ff 100644 --- a/admin/core/um-admin-actions.php +++ b/admin/core/um-admin-actions.php @@ -282,10 +282,10 @@ if ( !is_admin() || !current_user_can('manage_options') ) die(); //remove all confirm_user_password from DB - $wpdb->delete($wpdb->usermeta,['meta_key'=>'confirm_user_password']); + $wpdb->delete($wpdb->usermeta,array('meta_key'=>'confirm_user_password') ); //then reset submitted - $wpdb->update($wpdb->usermeta,['meta_value'=>''],['meta_key'=>'submitted']); + $wpdb->update($wpdb->usermeta,array('meta_value'=>''),array('meta_key'=>'submitted') ); //then set flag that update is complete and redirect to admin home update_option( 'um_passwords_secured', 1 ); diff --git a/admin/core/um-admin-notices.php b/admin/core/um-admin-notices.php index fd2b3ebd..ebf80174 100644 --- a/admin/core/um-admin-notices.php +++ b/admin/core/um-admin-notices.php @@ -160,8 +160,8 @@ class UM_Admin_Notices { switch($update) { case 'confirm_delete': - - $confirm_uri = sanitize_text_field( urldecode($_REQUEST['_wp_http_referer']) ); + $wp_http_referer = isset( $_REQUEST['_wp_http_referer'] ) ? $_REQUEST['_wp_http_referer']: ''; + $confirm_uri = sanitize_text_field( urldecode( $wp_http_referer ) ); $users = ''; if( isset( $_REQUEST['user'] ) ){ diff --git a/admin/core/um-admin-users.php b/admin/core/um-admin-users.php index 229aa8cf..bdb5dda9 100644 --- a/admin/core/um-admin-users.php +++ b/admin/core/um-admin-users.php @@ -208,8 +208,8 @@ class UM_Admin_Users { $users = $_REQUEST['users']; $bulk_action = current( array_filter( $_REQUEST['um_bulk_action']) ); - - if ( in_array('um_delete', $bulk_action ) > -1 ) { // this needs confirmation + + if ( 'um_delete' == $bulk_action ) { // this needs confirmation $uri = admin_url('users.php'); $userids = array_map( 'intval', (array) $_REQUEST['users'] ); @@ -254,9 +254,13 @@ class UM_Admin_Users { } // filter by user role - if ( isset($_REQUEST['um_filter_role']) && ( ! isset( $_REQUEST['new_role'] ) || empty( $_REQUEST['new_role'] ) ) && $_REQUEST['um_filter_role'] ) { + if ( isset($_REQUEST['um_filter_role']) && ! isset( $_REQUEST['um_filter_processed'] ) && ( ! isset( $_REQUEST['new_role'] ) || empty( $_REQUEST['new_role'] ) ) && $_REQUEST['um_filter_role'] ) { $filter_role = current( array_filter( $_REQUEST['um_filter_role'] ) ); - exit( wp_redirect( admin_url('users.php?um_role=' .$filter_role ) ) ); + $uri = add_query_arg('um_role',$filter_role); + $uri = add_query_arg('s',$_REQUEST['s'], $uri); + $uri = add_query_arg('um_filter_processed',true, $uri); + + exit( wp_redirect( $uri ) ); } } @@ -276,8 +280,9 @@ class UM_Admin_Users { query->get_roles(); + $um_filter_role = isset( $_REQUEST['um_filter_role'] )? current( array_filter($_REQUEST['um_filter_role']) ):''; foreach( $roles as $role => $role_name ) { ?> - + diff --git a/core/um-actions-form.php b/core/um-actions-form.php index 151dcf6b..8ead6541 100644 --- a/core/um-actions-form.php +++ b/core/um-actions-form.php @@ -92,11 +92,13 @@ if ( $words != '' ) { $words = array_map("rtrim", explode("\n", $words)); - foreach( $fields as $key => $array ) { - if ( isset( $args[$key] ) && !empty( $args[$key] ) ) { - if ( isset($array['validate']) && in_array( $array['validate'], array('unique_username','unique_email','unique_username_or_email') ) ) { - if ( !$ultimatemember->form->has_error( $key ) && in_array( $args[$key], $words ) ) { - $ultimatemember->form->add_error( $key, __('You are not allowed to use this word as your username.','ultimatemember') ); + if( isset( $fields ) && ! empty( $key ) ){ + foreach( $fields as $key => $array ) { + if ( isset( $args[$key] ) && !empty( $args[$key] ) ) { + if ( isset($array['validate']) && in_array( $array['validate'], array('unique_username','unique_email','unique_username_or_email') ) ) { + if ( !$ultimatemember->form->has_error( $key ) && in_array( $args[$key], $words ) ) { + $ultimatemember->form->add_error( $key, __('You are not allowed to use this word as your username.','ultimatemember') ); + } } } } @@ -153,229 +155,249 @@ $mode = $args['mode']; $fields = unserialize( $args['custom_fields'] ); - foreach( $fields as $key => $array ) { - - $array = apply_filters('um_get_custom_field_array', $array, $fields ); + if( isset( $fields ) && ! empty( $fields ) ){ + foreach( $fields as $key => $array ) { + + $array = apply_filters('um_get_custom_field_array', $array, $fields ); - if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) { - $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); - } - - if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { - $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); - } - - if ( isset( $array['type'] ) && $array['type'] == 'multiselect' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { - $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); - } - - if ( $key == 'role_select' || $key == 'role_radio' ) { - if ( isset( $array['required'] ) && $array['required'] == 1 && ( !isset( $args['role'] ) || empty( $args['role'] ) ) ) { - $ultimatemember->form->add_error('role', __('Please specify account type.','ultimatemember') ); + if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) { + $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); } - } - - if ( isset( $args[$key] ) ) { + + if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { + $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); + } + + if ( isset( $array['type'] ) && $array['type'] == 'multiselect' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { + $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); + } + + if ( $key == 'role_select' || $key == 'role_radio' ) { + if ( isset( $array['required'] ) && $array['required'] == 1 && ( !isset( $args['role'] ) || empty( $args['role'] ) ) ) { + $ultimatemember->form->add_error('role', __('Please specify account type.','ultimatemember') ); + } + } + + if ( isset( $args[$key] ) ) { - if ( isset( $array['required'] ) && $array['required'] == 1 ) { - if ( !isset($args[$key]) || $args[$key] == '' ) { - $ultimatemember->form->add_error($key, sprintf( __('%s is required','ultimatemember'), $array['label'] ) ); + if ( isset( $array['required'] ) && $array['required'] == 1 ) { + if ( !isset($args[$key]) || $args[$key] == '' ) { + $ultimatemember->form->add_error($key, sprintf( __('%s is required','ultimatemember'), $array['label'] ) ); + } } - } - - if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) { - if ( str_word_count( $args[$key] ) > $array['max_words'] ) { - $ultimatemember->form->add_error($key, sprintf(__('You are only allowed to enter a maximum of %s words','ultimatemember'), $array['max_words']) ); - } - } - - if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) { - if ( $args[$key] && strlen( utf8_decode( $args[$key] ) ) < $array['min_chars'] ) { - $ultimatemember->form->add_error($key, sprintf(__('Your %s must contain at least %s characters','ultimatemember'), $array['label'], $array['min_chars']) ); - } - } - - if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) { - if ( $args[$key] && strlen( utf8_decode( $args[$key] ) ) > $array['max_chars'] ) { - $ultimatemember->form->add_error($key, sprintf(__('Your %s must contain less than %s characters','ultimatemember'), $array['label'], $array['max_chars']) ); - } - } - - if ( isset( $array['html'] ) && $array['html'] == 0 ) { - if ( wp_strip_all_tags( $args[$key] ) != trim( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('You can not use HTML tags here','ultimatemember') ); - } - } - - if ( isset( $array['force_good_pass'] ) && $array['force_good_pass'] == 1 ) { - if ( !$ultimatemember->validation->strong_pass( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('Your password must contain at least one lowercase letter, one capital letter and one number','ultimatemember') ); - } - } - - if ( isset( $array['force_confirm_pass'] ) && $array['force_confirm_pass'] == 1 ) { - if ( $args[ 'confirm_' . $key] == '' && !$ultimatemember->form->has_error($key) ) { - $ultimatemember->form->add_error( 'confirm_' . $key , __('Please confirm your password','ultimatemember') ); - } - if ( $args[ 'confirm_' . $key] != $args[$key] && !$ultimatemember->form->has_error($key) ) { - $ultimatemember->form->add_error( 'confirm_' . $key , __('Your passwords do not match','ultimatemember') ); - } - } - - if ( isset( $array['min_selections'] ) && $array['min_selections'] > 0 ) { - if ( ( !isset($args[$key]) ) || ( isset( $args[$key] ) && is_array($args[$key]) && count( $args[$key] ) < $array['min_selections'] ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please select at least %s choices','ultimatemember'), $array['min_selections'] ) ); - } - } - - if ( isset( $array['max_selections'] ) && $array['max_selections'] > 0 ) { - if ( isset( $args[$key] ) && is_array($args[$key]) && count( $args[$key] ) > $array['max_selections'] ) { - $ultimatemember->form->add_error($key, sprintf(__('You can only select up to %s choices','ultimatemember'), $array['max_selections'] ) ); - } - } - - if ( isset( $array['validate'] ) && !empty( $array['validate'] ) ) { - - switch( $array['validate'] ) { - case 'custom': - $custom = $array['custom_validate']; - do_action("um_custom_field_validation_{$custom}", $key, $array, $args ); - break; - - case 'numeric': - if ( $args[$key] && !is_numeric( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('Please enter numbers only in this field','ultimatemember') ); - } - break; - - case 'phone_number': - if ( !$ultimatemember->validation->is_phone_number( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('Please enter a valid phone number','ultimatemember') ); - } - break; - - case 'youtube_url': - if ( !$ultimatemember->validation->is_url( $args[$key], 'youtube.com' ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); - } - break; - - case 'soundcloud_url': - if ( !$ultimatemember->validation->is_url( $args[$key], 'soundcloud.com' ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); - } - break; - - case 'facebook_url': - if ( !$ultimatemember->validation->is_url( $args[$key], 'facebook.com' ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); - } - break; - - case 'twitter_url': - if ( !$ultimatemember->validation->is_url( $args[$key], 'twitter.com' ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); - } - break; - - case 'instagram_url': - if ( !$ultimatemember->validation->is_url( $args[$key], 'instagram.com' ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); - } - break; - - case 'google_url': - if ( !$ultimatemember->validation->is_url( $args[$key], 'plus.google.com' ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); - } - break; - - case 'linkedin_url': - if ( !$ultimatemember->validation->is_url( $args[$key], 'linkedin.com' ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); - } - break; - - case 'url': - if ( !$ultimatemember->validation->is_url( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('Please enter a valid URL','ultimatemember') ); - } - break; - - case 'skype': - if ( !$ultimatemember->validation->is_url( $args[$key], 'skype.com' ) ) { - $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); - } - break; - - case 'unique_username': - - if ( $args[$key] == '' ) { - $ultimatemember->form->add_error($key, __('You must provide a username','ultimatemember') ); - } else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) { - $ultimatemember->form->add_error($key, __('Your username is already taken','ultimatemember') ); - } else if ( is_email( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('Username cannot be an email','ultimatemember') ); - } else if ( !$ultimatemember->validation->safe_username( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('Your username contains invalid characters','ultimatemember') ); - } - - break; - - case 'unique_username_or_email': - - if ( $args[$key] == '' ) { - $ultimatemember->form->add_error($key, __('You must provide a username','ultimatemember') ); - } else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) { - $ultimatemember->form->add_error($key, __('Your username is already taken','ultimatemember') ); - } else if ( $mode == 'register' && email_exists( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); - } else if ( !$ultimatemember->validation->safe_username( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('Your username contains invalid characters','ultimatemember') ); - } - - break; - - case 'unique_email': - - if ( in_array( $key, array('user_email') ) ) { + if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) { + if ( str_word_count( $args[$key] ) > $array['max_words'] ) { + $ultimatemember->form->add_error($key, sprintf(__('You are only allowed to enter a maximum of %s words','ultimatemember'), $array['max_words']) ); + } + } + + if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) { + if ( $args[$key] && strlen( utf8_decode( $args[$key] ) ) < $array['min_chars'] ) { + $ultimatemember->form->add_error($key, sprintf(__('Your %s must contain at least %s characters','ultimatemember'), $array['label'], $array['min_chars']) ); + } + } + + if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) { + if ( $args[$key] && strlen( utf8_decode( $args[$key] ) ) > $array['max_chars'] ) { + $ultimatemember->form->add_error($key, sprintf(__('Your %s must contain less than %s characters','ultimatemember'), $array['label'], $array['max_chars']) ); + } + } + + if ( isset( $array['html'] ) && $array['html'] == 0 ) { + if ( wp_strip_all_tags( $args[$key] ) != trim( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('You can not use HTML tags here','ultimatemember') ); + } + } + + if ( isset( $array['force_good_pass'] ) && $array['force_good_pass'] == 1 ) { + if ( !$ultimatemember->validation->strong_pass( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('Your password must contain at least one lowercase letter, one capital letter and one number','ultimatemember') ); + } + } + + if ( isset( $array['force_confirm_pass'] ) && $array['force_confirm_pass'] == 1 ) { + if ( $args[ 'confirm_' . $key] == '' && !$ultimatemember->form->has_error($key) ) { + $ultimatemember->form->add_error( 'confirm_' . $key , __('Please confirm your password','ultimatemember') ); + } + if ( $args[ 'confirm_' . $key] != $args[$key] && !$ultimatemember->form->has_error($key) ) { + $ultimatemember->form->add_error( 'confirm_' . $key , __('Your passwords do not match','ultimatemember') ); + } + } + + if ( isset( $array['min_selections'] ) && $array['min_selections'] > 0 ) { + if ( ( !isset($args[$key]) ) || ( isset( $args[$key] ) && is_array($args[$key]) && count( $args[$key] ) < $array['min_selections'] ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please select at least %s choices','ultimatemember'), $array['min_selections'] ) ); + } + } + + if ( isset( $array['max_selections'] ) && $array['max_selections'] > 0 ) { + if ( isset( $args[$key] ) && is_array($args[$key]) && count( $args[$key] ) > $array['max_selections'] ) { + $ultimatemember->form->add_error($key, sprintf(__('You can only select up to %s choices','ultimatemember'), $array['max_selections'] ) ); + } + } + + if ( isset( $array['validate'] ) && !empty( $array['validate'] ) ) { + + switch( $array['validate'] ) { + + case 'custom': + $custom = $array['custom_validate']; + do_action("um_custom_field_validation_{$custom}", $key, $array, $args ); + break; - 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] ) ) { - $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') ); + case 'numeric': + if ( $args[$key] && !is_numeric( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('Please enter numbers only in this field','ultimatemember') ); + } + break; + + case 'phone_number': + if ( !$ultimatemember->validation->is_phone_number( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('Please enter a valid phone number','ultimatemember') ); + } + break; + + case 'youtube_url': + if ( !$ultimatemember->validation->is_url( $args[$key], 'youtube.com' ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); + } + break; + + case 'soundcloud_url': + if ( !$ultimatemember->validation->is_url( $args[$key], 'soundcloud.com' ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); + } + break; + + case 'facebook_url': + if ( !$ultimatemember->validation->is_url( $args[$key], 'facebook.com' ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); + } + break; + + case 'twitter_url': + if ( !$ultimatemember->validation->is_url( $args[$key], 'twitter.com' ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); + } + break; + + case 'instagram_url': + if ( !$ultimatemember->validation->is_url( $args[$key], 'instagram.com' ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); + } + break; + + case 'google_url': + if ( !$ultimatemember->validation->is_url( $args[$key], 'plus.google.com' ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); + } + break; + + case 'linkedin_url': + if ( !$ultimatemember->validation->is_url( $args[$key], 'linkedin.com' ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); + } + break; + + case 'url': + if ( !$ultimatemember->validation->is_url( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('Please enter a valid URL','ultimatemember') ); + } + break; + + case 'skype': + if ( !$ultimatemember->validation->is_url( $args[$key], 'skype.com' ) ) { + $ultimatemember->form->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimatemember'), $array['label'] ) ); + } + break; + + case 'unique_username': + + if ( $args[$key] == '' ) { + $ultimatemember->form->add_error($key, __('You must provide a username','ultimatemember') ); + } else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) { + $ultimatemember->form->add_error($key, __('Your username is already taken','ultimatemember') ); + } else if ( is_email( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('Username cannot be an email','ultimatemember') ); } else if ( !$ultimatemember->validation->safe_username( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('Your email contains invalid characters','ultimatemember') ); - } - - } else { - - if ( $args[$key] != '' && !is_email($args[$key]) ) { - $ultimatemember->form->add_error($key, __('This is not a valid email','ultimatemember') ); - } else if ( $args[$key] != '' && email_exists( $args[$key] ) ) { - $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); + $ultimatemember->form->add_error($key, __('Your username contains invalid characters','ultimatemember') ); } - } - + break; + + case 'unique_username_or_email': + + if ( $args[$key] == '' ) { + $ultimatemember->form->add_error($key, __('You must provide a username','ultimatemember') ); + } else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) { + $ultimatemember->form->add_error($key, __('Your username is already taken','ultimatemember') ); + } else if ( $mode == 'register' && email_exists( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); + } else if ( !$ultimatemember->validation->safe_username( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('Your username contains invalid characters','ultimatemember') ); + } + + break; + + case 'unique_email': + + if ( in_array( $key, array('user_email') ) ) { + + 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] ) ) { + $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') ); + } else if ( !$ultimatemember->validation->safe_username( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('Your email contains invalid characters','ultimatemember') ); + } + + } else { + + if ( $args[$key] != '' && !is_email($args[$key]) ) { + $ultimatemember->form->add_error($key, __('This is not a valid email','ultimatemember') ); + } else if ( $args[$key] != '' && email_exists( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); + } + + } + + break; + + case 'unique_value': + + if ( $args[$key] != '' ) { + + $args_unique_meta = array( + 'meta_key' => $key, + 'meta_value' => $args[ $key ], + 'compare' => '=', + 'exclude' => array( $args['user_id'] ), + ); + + $meta_key_exists = get_users( $args_unique_meta ); + + if( $meta_key_exists ){ + $ultimatemember->form->add_error( $key , __('You must provide a unique value','ultimatemember') ); + } + } break; - + + } + } - + } - } - - if ( isset( $args['description'] ) ) { - $max_chars = um_get_option('profile_bio_maxchars'); - if ( strlen( utf8_decode( $args['description'] ) ) > $max_chars && $max_chars ) { - $ultimatemember->form->add_error('description', sprintf(__('Your user description must contain less than %s characters','ultimatemember'), $max_chars ) ); + if ( isset( $args['description'] ) ) { + $max_chars = um_get_option('profile_bio_maxchars'); + if ( strlen( utf8_decode( $args['description'] ) ) > $max_chars && $max_chars ) { + $ultimatemember->form->add_error('description', sprintf(__('Your user description must contain less than %s characters','ultimatemember'), $max_chars ) ); + } } - } - - } // end if ( isset in args array ) - + + } // end if ( isset in args array ) + } } \ No newline at end of file