From 40f4d65ed5f99d924b4157bf898527b177383e31 Mon Sep 17 00:00:00 2001 From: jonfalcon Date: Thu, 11 Feb 2016 11:32:03 -0800 Subject: [PATCH 1/4] Fix blocked words --- core/um-actions-form.php | 182 +++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 92 deletions(-) diff --git a/core/um-actions-form.php b/core/um-actions-form.php index 708c8ea8..253ab682 100644 --- a/core/um-actions-form.php +++ b/core/um-actions-form.php @@ -6,69 +6,69 @@ add_action('um_submit_form_errors_hook__registration', 'um_submit_form_errors_hook__registration', 10); function um_submit_form_errors_hook__registration($args){ global $ultimatemember; - + $can_register = get_option('users_can_register'); if ( !$can_register ) { exit( wp_redirect( esc_url( add_query_arg('err', 'registration_disabled') ) ) ); } - + } - + /*** *** @Error handling: blocked emails ***/ add_action('um_submit_form_errors_hook__blockedemails', 'um_submit_form_errors_hook__blockedemails', 10); function um_submit_form_errors_hook__blockedemails($args){ global $ultimatemember; - + $emails = um_get_option('blocked_emails'); if ( !$emails ) return; - + $emails = array_map("rtrim", explode("\n", $emails)); - + if ( isset( $args['user_email'] ) && is_email( $args['user_email'] ) ) { - + $domain = explode('@', $args['user_email'] ); $check_domain = str_replace($domain[0], '*', $args['user_email']); if ( in_array( $args['user_email'], $emails ) ) exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_email') ) ) ); - + if ( in_array( $check_domain, $emails ) ) exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_domain') ) ) ); - + } - + if ( isset( $args['username'] ) && is_email( $args['username'] ) ) { - + $domain = explode('@', $args['username'] ); $check_domain = str_replace($domain[0], '*', $args['username']); - + if ( in_array( $args['username'], $emails ) ) exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_email') ) ) ); if ( in_array( $check_domain, $emails ) ) exit( wp_redirect( esc_url( add_query_arg('err', 'blocked_domain') ) ) ); - + } - + } - + /*** *** @Error handling: blocked IPs ***/ add_action('um_submit_form_errors_hook__blockedips', 'um_submit_form_errors_hook__blockedips', 10); function um_submit_form_errors_hook__blockedips($args){ global $ultimatemember; - + $ips = um_get_option('blocked_ips'); if ( !$ips ) return; - + $ips = array_map("rtrim", explode("\n", $ips)); $user_ip = um_user_ip(); - + foreach($ips as $ip) { $ip = str_replace('*','',$ip); if (strpos($user_ip, $ip) === 0) { @@ -76,72 +76,70 @@ } } } - + /*** *** @Error handling: blocked words during sign up ***/ add_action('um_submit_form_errors_hook__blockedwords', 'um_submit_form_errors_hook__blockedwords', 10); function um_submit_form_errors_hook__blockedwords($args){ global $ultimatemember; - + $form_id = $args['form_id']; $mode = $args['mode']; $fields = unserialize( $args['custom_fields'] ); - + $words = um_get_option('blocked_words'); if ( $words != '' ) { - + $words = array_map("rtrim", explode("\n", $words)); - if( isset( $fields ) && ! empty( $key ) ){ + if( isset( $fields ) ){ 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($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') ); } } } } } - + } - + /*** *** @Error handling ***/ add_action('um_submit_form_errors_hook', 'um_submit_form_errors_hook', 10); function um_submit_form_errors_hook( $args ){ global $ultimatemember; - + $form_id = $args['form_id']; - + $mode = $args['mode']; - + $fields = unserialize( $args['custom_fields'] ); - + if ( $mode == 'register' ){ - + do_action("um_submit_form_errors_hook__registration", $args ); - + } - + do_action("um_submit_form_errors_hook__blockedips", $args ); do_action("um_submit_form_errors_hook__blockedemails", $args ); if ( $mode == 'login' ) { - + do_action('um_submit_form_errors_hook_login', $args ); do_action('um_submit_form_errors_hook_logincheck', $args ); - + } else { - + do_action('um_submit_form_errors_hook_', $args ); do_action("um_submit_form_errors_hook__blockedwords", $args ); - + } - + } /*** @@ -150,34 +148,34 @@ add_action('um_submit_form_errors_hook_', 'um_submit_form_errors_hook_', 10); function um_submit_form_errors_hook_( $args ){ global $ultimatemember; - + $form_id = $args['form_id']; $mode = $args['mode']; $fields = unserialize( $args['custom_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( $args[$key] ) ) { if ( isset( $array['required'] ) && $array['required'] == 1 ) { @@ -185,37 +183,37 @@ $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') ); @@ -224,58 +222,58 @@ $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'] ) ); @@ -287,13 +285,13 @@ $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'] ) ); @@ -305,21 +303,21 @@ $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] ) ) ) { @@ -329,11 +327,11 @@ } 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] ) ) ) { @@ -343,13 +341,13 @@ } 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] ) ) { @@ -359,23 +357,23 @@ } 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 ], @@ -384,26 +382,26 @@ ); $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 ) ); } } - + } // end if ( isset in args array ) } - } \ No newline at end of file + } From 33b693d3c33e090427a9d05f1c668910434ff532 Mon Sep 17 00:00:00 2001 From: jonfalcon Date: Mon, 15 Feb 2016 17:52:47 -0800 Subject: [PATCH 2/4] Fix searching with space --- core/um-filters-members.php | 102 ++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/core/um-filters-members.php b/core/um-filters-members.php index 6473146b..547634d4 100644 --- a/core/um-filters-members.php +++ b/core/um-filters-members.php @@ -1,5 +1,5 @@ permalinks->get_query_array(); - + foreach( $ultimatemember->members->core_search_fields as $key ) { if ( isset( $query[$key] ) ) { - $query_args['search'] = '*' . $query[$key] . '*'; + $query_args['search'] = '*' . trim($query[$key]) . '*'; } } return $query_args; } - + /*** *** @Remove users we do not need to show in directory ***/ function um_remove_special_users_from_list( $query_args, $args ) { global $ultimatemember; extract( $args ); - + if ( !um_user_can('can_edit_everyone') ) { - + $query_args['meta_query'][] = array( 'key' => 'account_status', 'value' => 'approved', 'compare' => '=' ); - + } - + $query_args['meta_query'][] = array( 'key' => 'hide_in_members', 'value' => '', @@ -50,23 +50,23 @@ return $query_args; } - + /*** *** @adds search parameters ***/ function um_add_search_to_query( $query_args, $args ){ global $ultimatemember; extract( $args ); - + if ( isset( $_REQUEST['um_search'] ) ) { - + $query = $ultimatemember->permalinks->get_query_array(); if ( $query && is_array( $query ) ) { foreach( $query as $field => $value ) { if(in_array($field, array('members_page'))) continue; - + if ( in_array( $field, array('gender') ) ) { $operator = '='; } else { @@ -78,53 +78,53 @@ } if ( $value && $field != 'um_search' && $field != 'page_id' ) { - + if ( !in_array( $field, $ultimatemember->members->core_search_fields ) ) { - + if ( strstr($field, 'role_' ) ) { $field = 'role'; $operator = '='; } - + $query_args['meta_query'][] = array( 'key' => $field, - 'value' => $value, + 'value' => trim($value), 'compare' => $operator, ); - + } - + } - + } } } - + // allow filtering $query_args = apply_filters('um_query_args_filter', $query_args ); - + if ( count ($query_args['meta_query']) == 1 ) { unset( $query_args['meta_query'] ); } return $query_args; - + } - + /*** *** @adds main parameters ***/ function um_prepare_user_query_args($query_args, $args){ global $ultimatemember; extract( $args ); - + $query_args['fields'] = 'ID'; - + $query_args['number'] = 0; - + $query_args['meta_query']['relation'] = 'AND'; - + // must have a profile photo if ( $has_profile_photo == 1 ) { $query_args['meta_query'][] = array( @@ -133,7 +133,7 @@ 'compare' => '!=' ); } - + // must have a cover photo if ( $has_cover_photo == 1 ) { $query_args['meta_query'][] = array( @@ -142,7 +142,7 @@ 'compare' => '!=' ); } - + // show specific usernames if ( isset( $show_these_users ) && $show_these_users && is_array( $show_these_users ) ) { foreach( $show_these_users as $username ) { @@ -150,52 +150,52 @@ } $query_args['include'] = $users_array; } - - // add roles to appear in directory + + // add roles to appear in directory if ( !empty( $roles ) ) { - + $query_args['meta_query'][] = array( 'key' => 'role', 'value' => $roles, 'compare' => 'IN' ); - + } - + // sort members by $query_args['order'] = 'ASC'; - + if ( isset( $sortby ) ) { - + if ( $sortby == 'other' && $sortby_custom ) { - + $query_args['meta_key'] = $sortby_custom; $query_args['orderby'] = 'meta_value, display_name'; - + } else if ( in_array( $sortby, array( 'last_name', 'first_name' ) ) ) { - + $query_args['meta_key'] = $sortby; $query_args['orderby'] = 'meta_value'; - + } else { - + if ( strstr( $sortby, '_desc' ) ) {$sortby = str_replace('_desc','',$sortby);$order = 'DESC';} if ( strstr( $sortby, '_asc' ) ) {$sortby = str_replace('_asc','',$sortby);$order = 'ASC';} $query_args['orderby'] = $sortby; - + } - + if ( isset( $order ) ) { $query_args['order'] = $order; } - + $query_args = apply_filters('um_modify_sortby_parameter', $query_args, $sortby); } - + return $query_args; } - + /*** *** @sorting by last login date ***/ @@ -208,7 +208,7 @@ } return $query_args; } - + /*** *** @hook in the member results array ***/ @@ -220,6 +220,6 @@ } else { $result['no_users'] = 0; } - + return $result; - } \ No newline at end of file + } From 8566dd6afab1830edc2977f2ceb0ff6468486a95 Mon Sep 17 00:00:00 2001 From: jonfalcon Date: Tue, 16 Feb 2016 15:10:51 -0800 Subject: [PATCH 3/4] Add password confirmation validation --- assets/css/um-styles.css | 7 +- assets/js/um-functions.js | 327 ++++++++++++++++++++------------------ 2 files changed, 180 insertions(+), 154 deletions(-) diff --git a/assets/css/um-styles.css b/assets/css/um-styles.css index bc6302a8..6cbcc5bf 100644 --- a/assets/css/um-styles.css +++ b/assets/css/um-styles.css @@ -750,4 +750,9 @@ small.um-max-filesize { } small.um-max-filesize span{ font-size: 12px; -} \ No newline at end of file +} + +.um-form .um-field .um-field-area input.um-form-field.um-validate-not-matched, +.um-form .um-field .um-field-area input.um-form-field.um-validate-not-matched:focus { + border-color: #DB2929 !important; +} diff --git a/assets/js/um-functions.js b/assets/js/um-functions.js index f834753c..e202ea69 100644 --- a/assets/js/um-functions.js +++ b/assets/js/um-functions.js @@ -8,15 +8,15 @@ function um_conditional(){ var found = 0; var um_field_key = jQuery(this).data('key'); for (var i = 0; i < 5; i++) { - + var action0 = jQuery(this).data('cond-'+i+'-action'); var field0 = jQuery(this).data('cond-'+i+'-field'); var operator0 = jQuery(this).data('cond-'+i+'-operator'); var value0 = jQuery(this).data('cond-'+i+'-value'); - - + + if ( action0 == 'show' && field0 == live_field && typeof value0 !== 'undefined' ) { - + if ( operator0 == 'empty' ) { if ( !live_value || live_value == '' || found > 0 ) { jQuery(this).fadeIn(); @@ -25,10 +25,10 @@ function um_conditional(){ jQuery(this).hide(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').hide(); um_reset_field('div.um-field[data-cond-'+i+'-field='+um_field_key+']'); - + } } - + if ( operator0 == 'not empty' ) { if ( live_value && live_value != '' || found > 0 ) { jQuery(this).fadeIn(); @@ -37,10 +37,10 @@ function um_conditional(){ jQuery(this).hide(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').hide(); um_reset_field('div.um-field[data-cond-'+i+'-field='+um_field_key+']'); - + } } - + if ( operator0 == 'equals to' ) { if ( value0 == live_value || found > 0 ) { jQuery(this).fadeIn(); @@ -49,10 +49,10 @@ function um_conditional(){ jQuery(this).hide(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').hide(); um_reset_field('div.um-field[data-cond-'+i+'-field='+um_field_key+']'); - + } } - + if ( operator0 == 'not equals' ) { if ( jQuery.isNumeric( value0 ) && parseInt( live_value ) != parseInt( value0 ) && live_value || found > 0 ) { jQuery(this).fadeIn(); @@ -64,10 +64,10 @@ function um_conditional(){ jQuery(this).hide(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').hide(); um_reset_field('div.um-field[data-cond-'+i+'-field='+um_field_key+']'); - + } } - + if ( operator0 == 'greater than' ) { if ( jQuery.isNumeric( value0 ) && parseInt( live_value ) > parseInt( value0 ) || found > 0) { jQuery(this).fadeIn(); @@ -76,10 +76,10 @@ function um_conditional(){ jQuery(this).hide(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').hide(); um_reset_field('div.um-field[data-cond-'+i+'-field='+um_field_key+']'); - + } } - + if ( operator0 == 'less than' ) { if ( jQuery.isNumeric( value0 ) && parseInt( live_value ) < parseInt( value0 ) && live_value || found > 0) { jQuery(this).fadeIn(); @@ -88,10 +88,10 @@ function um_conditional(){ jQuery(this).hide(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').hide(); um_reset_field('div.um-field[data-cond-'+i+'-field='+um_field_key+']'); - + } } - + if ( operator0 == 'contains' ) { if ( live_value && live_value.indexOf( value0 ) >= 0 || found > 0 ) { jQuery(this).fadeIn(); @@ -100,14 +100,14 @@ function um_conditional(){ jQuery(this).hide(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').hide(); um_reset_field('div.um-field[data-cond-'+i+'-field='+um_field_key+']'); - + } } - + } - + if ( action0 == 'hide' && field0 == live_field && typeof value0 !== 'undefined' ) { - + if ( operator0 == 'empty' ) { if ( !live_value || live_value == '' ) { jQuery(this).hide(); @@ -117,7 +117,7 @@ function um_conditional(){ } } - + if ( operator0 == 'not empty' ) { if ( live_value && live_value != '' ) { jQuery(this).hide(); @@ -125,10 +125,10 @@ function um_conditional(){ } else { jQuery(this).fadeIn(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').show(); - + } } - + if ( operator0 == 'equals to' ) { if ( value0 == live_value ) { jQuery(this).hide(); @@ -136,10 +136,10 @@ function um_conditional(){ } else { jQuery(this).fadeIn(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').show(); - + } } - + if ( operator0 == 'not equals' ) { if ( jQuery.isNumeric( value0 ) && parseInt( live_value ) != parseInt( value0 ) && live_value ) { jQuery(this).hide(); @@ -150,10 +150,10 @@ function um_conditional(){ } else { jQuery(this).fadeIn(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').show(); - + } } - + if ( operator0 == 'greater than' ) { if ( jQuery.isNumeric( value0 ) && parseInt( live_value ) > parseInt( value0 ) ) { jQuery(this).hide(); @@ -161,10 +161,10 @@ function um_conditional(){ } else { jQuery(this).fadeIn(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').show(); - + } } - + if ( operator0 == 'less than' ) { if ( jQuery.isNumeric( value0 ) && parseInt( live_value ) < parseInt( value0 ) && live_value ) { jQuery(this).hide(); @@ -172,10 +172,10 @@ function um_conditional(){ } else { jQuery(this).fadeIn(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').show(); - + } } - + if ( operator0 == 'contains' ) { if ( live_value && live_value.indexOf( value0 ) >= 0 ) { jQuery(this).hide(); @@ -183,41 +183,62 @@ function um_conditional(){ } else { jQuery(this).fadeIn(); jQuery('div.um-field[data-cond-'+i+'-field='+um_field_key+']').show(); - + } } //console.log( 'hide',i,value0, live_value ); } - + } }); } +function UM_check_password_matched() { + jQuery(document).on('input[data-key=user_password],input[data-key=confirm_user_password]').on('keyup', function(e) { + var value = jQuery('input[data-key=user_password]').val(); + var match = jQuery('input[data-key=confirm_user_password]').val(); + var field = jQuery('input[data-key=user_password],input[data-key=confirm_user_password]'); + + if(!value && !match) { + field.removeClass('um-validate-matched').removeClass('um-validate-not-matched'); + } else if(value !== match) { + field.removeClass('um-validate-matched').addClass('um-validate-not-matched'); + } else { + field.removeClass('um-validate-not-matched').addClass('um-validate-matched'); + } + }); +} +jQuery(document).ready(function(){ + if(jQuery('input[data-key=user_password],input[data-key=confirm_user_password]').length == 2) { + UM_check_password_matched(); + } +}) + function UM_hide_menus() { menu = jQuery('.um-dropdown'); menu.parents('div').find('a').removeClass('active'); menu.hide(); - + } function UM_domenus(){ jQuery('.um-dropdown').each(function(){ - + var menu = jQuery(this); var element = jQuery(this).attr('data-element'); var position = jQuery(this).attr('data-position'); - + jQuery(element).addClass('um-trigger-menu-on-'+menu.attr('data-trigger')); if ( jQuery(window).width() <= 1200 && element == 'div.um-profile-edit' ) { position = 'lc'; } - + if ( position == 'lc' ){ if ( 200 > jQuery(element).find('img').width() ) { @@ -225,9 +246,9 @@ function UM_domenus(){ } else { left_p = ( ( jQuery(element).width() - jQuery(element).find('img').width() ) / 2 ); } - + top_ = parseInt( jQuery(element).find('a').css('top') ); - + if ( top_ ) { top_p = jQuery(element).find('img').height() + 4 + top_; left_gap = 4; @@ -235,13 +256,13 @@ function UM_domenus(){ top_p = jQuery(element).find('img').height() + 4; left_gap = 0; } - + if ( top_p == 4 && element == 'div.um-cover' ) { top_p = jQuery(element).height() / 2 + ( menu.height() / 2 ); } else if ( top_p == 4 ) { top_p = jQuery(element).height() + 20; } - + gap_right = jQuery(element).width() + 17; menu.css({ 'top' : 0, @@ -250,17 +271,17 @@ function UM_domenus(){ 'right' : gap_right + 'px', 'text-align' : 'center' }); - + menu.find('.um-dropdown-arr').find('i').removeClass().addClass('um-icon-arrow-right-b'); - + menu.find('.um-dropdown-arr').css({ 'top' : '4px', 'left' : 'auto', 'right' : '-17px' }); - + } - + if ( position == 'bc' ){ if ( 200 > jQuery(element).find('img').width() ) { @@ -268,9 +289,9 @@ function UM_domenus(){ } else { left_p = ( ( jQuery(element).width() - jQuery(element).find('img').width() ) / 2 ); } - + top_ = parseInt( jQuery(element).find('a').css('top') ); - + if ( top_ ) { top_p = jQuery(element).find('img').height() + 4 + top_; left_gap = 4; @@ -278,7 +299,7 @@ function UM_domenus(){ top_p = jQuery(element).find('img').height() + 4; left_gap = 0; } - + if ( top_p == 4 && element == 'div.um-cover' ) { top_p = jQuery(element).height() / 2 + ( menu.height() / 2 ); } else if ( top_p == 4 ) { @@ -292,64 +313,64 @@ function UM_domenus(){ 'right' : 'auto', 'text-align' : 'center' }); - + menu.find('.um-dropdown-arr').find('i').removeClass().addClass('um-icon-arrow-up-b'); - + menu.find('.um-dropdown-arr').css({ 'top' : '-17px', 'left' : ( menu.width() / 2 ) - 12, 'right' : 'auto' }); - + } }); - + } function um_responsive(){ jQuery('.um').each(function(){ - + element_width = jQuery(this).width(); if ( element_width <= 340 ) { - + jQuery(this).removeClass('uimob340'); jQuery(this).removeClass('uimob500'); jQuery(this).removeClass('uimob800'); jQuery(this).removeClass('uimob960'); - + jQuery(this).addClass('uimob340'); } else if ( element_width <= 500 ) { - + jQuery(this).removeClass('uimob340'); jQuery(this).removeClass('uimob500'); jQuery(this).removeClass('uimob800'); jQuery(this).removeClass('uimob960'); - + jQuery(this).addClass('uimob500'); } else if ( element_width <= 800 ) { - + jQuery(this).removeClass('uimob340'); jQuery(this).removeClass('uimob500'); jQuery(this).removeClass('uimob800'); jQuery(this).removeClass('uimob960'); - + jQuery(this).addClass('uimob800'); } else if ( element_width <= 960 ) { - + jQuery(this).removeClass('uimob340'); jQuery(this).removeClass('uimob500'); jQuery(this).removeClass('uimob800'); jQuery(this).removeClass('uimob960'); - + jQuery(this).addClass('uimob960'); } else if ( element_width > 960 ) { - + jQuery(this).removeClass('uimob340'); jQuery(this).removeClass('uimob500'); jQuery(this).removeClass('uimob800'); @@ -360,13 +381,13 @@ function um_responsive(){ if ( jQuery('.um-account-nav').length > 0 && jQuery('.um-account-side').is(':visible') && jQuery('.um-account-tab:visible').length == 0 ) { jQuery('.um-account-side li a.current').trigger('click'); } - + jQuery(this).css('opacity',1); }); jQuery('.um-cover, .um-member-cover').each(function(){ - + var elem = jQuery(this); var ratio = elem.data('ratio'); var width = elem.width(); @@ -375,7 +396,7 @@ function um_responsive(){ calcHeight = Math.round( width / ratios[0] ) + 'px'; elem.height( calcHeight ); elem.find('.um-cover-add').height( calcHeight ); - + }); jQuery('.um-members').each(function(){ @@ -383,7 +404,7 @@ function um_responsive(){ }); UM_domenus(); - + } function UM_Member_Grid( container ) { @@ -402,7 +423,7 @@ function initImageUpload_UM( trigger ) { } else { upload_help_text = ''; } - + if ( trigger.data('icon') ) { icon = ''; } else { @@ -434,42 +455,42 @@ function initImageUpload_UM( trigger ) { showFileCounter: false, showStatusAfterSuccess: true, onSubmit:function(files){ - + trigger.parents('.um-modal-body').find('.um-error-block').remove(); - + }, onSuccess:function(files,data,xhr){ - + trigger.selectedFiles = 0; - + data = jQuery.parseJSON(data); if (data.error && data.error != '') { trigger.parents('.um-modal-body').append('
'+data.error+'
'); trigger.parents('.um-modal-body').find('.upload-statusbar').hide(0); um_modal_responsive(); - + } else { jQuery.each( data, function(key, value) { - + var img_id = trigger.parents('.um-modal-body').find('.um-single-image-preview img'); var img_id_h = trigger.parents('.um-modal-body').find('.um-single-image-preview'); - + img_id.attr("src", value); img_id.load(function(){ - + trigger.parents('.um-modal-body').find('.um-modal-btn.um-finish-upload.disabled').removeClass('disabled'); trigger.parents('.um-modal-body').find('.ajax-upload-dragdrop,.upload-statusbar').hide(0); img_id_h.show(0); um_modal_responsive(); - + }); - + }); } - + } }); @@ -482,7 +503,7 @@ function initFileUpload_UM( trigger ) { } else { upload_help_text = ''; } - + if ( trigger.data('icon') ) { icon = ''; } else { @@ -494,7 +515,7 @@ function initFileUpload_UM( trigger ) { } else { upload_text = ''; } - + trigger.uploadFile({ url: um_scripts.fileupload, method: "POST", @@ -514,29 +535,29 @@ function initFileUpload_UM( trigger ) { showFileCounter: false, showStatusAfterSuccess: true, onSubmit:function(files){ - + trigger.parents('.um-modal-body').find('.um-error-block').remove(); - + }, onSuccess:function(files,data,xhr){ - + trigger.selectedFiles = 0; - + data = jQuery.parseJSON(data); if (data.error && data.error != '') { trigger.parents('.um-modal-body').append('
'+data.error+'
'); trigger.parents('.um-modal-body').find('.upload-statusbar').hide(0); um_modal_responsive(); - + } else { jQuery.each( data, function(key, value) { - + trigger.parents('.um-modal-body').find('.um-modal-btn.um-finish-upload.disabled').removeClass('disabled'); trigger.parents('.um-modal-body').find('.ajax-upload-dragdrop,.upload-statusbar').hide(0); trigger.parents('.um-modal-body').find('.um-single-file-preview').show(0); - + if (key == 'icon') { trigger.parents('.um-modal-body').find('.um-single-fileinfo i').removeClass().addClass(value); } else if ( key == 'icon_bg' ) { @@ -546,28 +567,28 @@ function initFileUpload_UM( trigger ) { } else { trigger.parents('.um-modal-body').find('.um-single-fileinfo a').attr('href', value); } - + }); - + um_modal_responsive(); - + } - + } }); - + } function initCrop_UM() { var target_img = jQuery('.um-modal:visible .um-single-image-preview img'); var target_img_parent = jQuery('.um-modal:visible .um-single-image-preview'); - + var crop_data = target_img.parent().attr('data-crop'); var min_width = target_img.parent().attr('data-min_width'); var min_height = target_img.parent().attr('data-min_height'); var ratio = target_img.parent().attr('data-ratio'); - + if ( jQuery('.um-modal').find('#um_upload_single').attr('data-ratio') ) { var ratio = jQuery('.um-modal').find('#um_upload_single').attr('data-ratio'); var ratio_split = ratio.split(':'); @@ -575,9 +596,9 @@ function initCrop_UM() { } if ( target_img.length ) { - + if ( target_img.attr('src') != '' ) { - + var max_height = jQuery(window).height() - ( jQuery('.um-modal-footer a').height() + 20 ) - 50 - ( jQuery('.um-modal-header:visible').height() ); target_img.css({'height' : 'auto'}); target_img_parent.css({'height' : 'auto'}); @@ -590,7 +611,7 @@ function initCrop_UM() { } if ( crop_data == 'square' ) { - + var opts = { minWidth: min_width, minHeight: min_height, @@ -603,7 +624,7 @@ function initCrop_UM() { target_img.parent().attr('data-coord', Math.round(data.x) + ',' + Math.round(data.y) + ',' + Math.round(data.width) + ',' + Math.round(data.height) ); } }; - + } else if ( crop_data == 'cover' ) { var opts = { @@ -618,9 +639,9 @@ function initCrop_UM() { target_img.parent().attr('data-coord', Math.round(data.x) + ',' + Math.round(data.y) + ',' + Math.round(data.width) + ',' + Math.round(data.height) ); } }; - + } else if ( crop_data == 'user' ) { - + var opts = { minWidth: min_width, minHeight: min_height, @@ -633,169 +654,169 @@ function initCrop_UM() { target_img.parent().attr('data-coord', Math.round(data.x) + ',' + Math.round(data.y) + ',' + Math.round(data.width) + ',' + Math.round(data.height) ); } }; - + } if ( crop_data != 0 ) { target_img.cropper( opts ); } - + } } - + } function um_new_modal( id, size, isPhoto, source ){ - + var modal = jQuery('body').find('.um-modal-overlay'); - + if ( modal.length == 0 ) { jQuery('.tipsy').hide(); UM_hide_menus(); - + jQuery('body,html,textarea').css("overflow", "hidden"); - + jQuery(document).bind("touchmove", function(e){e.preventDefault();}); jQuery('.um-modal').on('touchmove', function(e){e.stopPropagation();}); - + if ( isPhoto ) { jQuery('body').append('
'); } else { jQuery('body').append('
'); } - + jQuery('#' + id).prependTo('.um-modal'); - + if ( isPhoto ) { - + jQuery('.um-modal').find('.um-modal-photo').html(''); - + var photo_ = jQuery('.um-modal-photo img'); var photo_maxw = jQuery(window).width() - 60; var photo_maxh = jQuery(window).height() - ( jQuery(window).height() * 0.25 ); photo_.attr("src", source); photo_.load(function(){ - + jQuery('#' + id).show(); jQuery('.um-modal').show(); - + photo_.css({'opacity': 0}); photo_.css({'max-width': photo_maxw }); photo_.css({'max-height': photo_maxh }); - + jQuery('.um-modal').css({ 'width': photo_.width(), 'margin-left': '-' + photo_.width() / 2 + 'px' }); - + photo_.animate({'opacity' : 1}, 1000); - + um_modal_responsive(); - + }); } else { - + jQuery('#' + id).show(); jQuery('.um-modal').show(); um_modal_size( size ); - + initImageUpload_UM( jQuery('.um-modal:visible').find('.um-single-image-upload') ); initFileUpload_UM( jQuery('.um-modal:visible').find('.um-single-file-upload') ); - + um_modal_responsive(); - + } - + } - + } function um_modal_responsive() { - + var modal = jQuery('.um-modal:visible'); var photo_modal = jQuery('.um-modal-body.photo:visible'); - + if ( photo_modal.length ) { - + modal.removeClass('uimob340'); modal.removeClass('uimob500'); - + var photo_ = jQuery('.um-modal-photo img'); var photo_maxw = jQuery(window).width() - 60; var photo_maxh = jQuery(window).height() - ( jQuery(window).height() * 0.25 ); - + photo_.css({'opacity': 0}); photo_.css({'max-width': photo_maxw }); photo_.css({'max-height': photo_maxh }); - + jQuery('.um-modal').css({ 'width': photo_.width(), 'margin-left': '-' + photo_.width() / 2 + 'px' }); - + photo_.animate({'opacity' : 1}, 1000); var half_gap = ( jQuery(window).height() - modal.innerHeight() ) / 2 + 'px'; modal.animate({ 'bottom' : half_gap }, 300); - + } else if ( modal.length ) { var element_width = jQuery(window).width(); - + modal.removeClass('uimob340'); modal.removeClass('uimob500'); - + if ( element_width <= 340 ) { - + modal.addClass('uimob340'); initCrop_UM(); modal.animate({ 'bottom' : 0 }, 300); - + } else if ( element_width <= 500 ) { - + modal.addClass('uimob500'); initCrop_UM(); modal.animate({ 'bottom' : 0 }, 300); - + } else if ( element_width <= 800 ) { - + initCrop_UM(); var half_gap = ( jQuery(window).height() - modal.innerHeight() ) / 2 + 'px'; modal.animate({ 'bottom' : half_gap }, 300); - + } else if ( element_width <= 960 ) { - + initCrop_UM(); var half_gap = ( jQuery(window).height() - modal.innerHeight() ) / 2 + 'px'; modal.animate({ 'bottom' : half_gap }, 300); - + } else if ( element_width > 960 ) { - + initCrop_UM(); var half_gap = ( jQuery(window).height() - modal.innerHeight() ) / 2 + 'px'; modal.animate({ 'bottom' : half_gap }, 300); - + } - + } } function um_remove_modal(){ jQuery('img.cropper-hidden').cropper('destroy'); - + jQuery('body,html,textarea').css("overflow", "auto"); - + jQuery(document).unbind('touchmove'); jQuery('.um-modal div[id^="um_"]').hide().appendTo('body'); jQuery('.um-modal,.um-modal-overlay').remove(); - + } function um_modal_size( aclass ) { @@ -843,15 +864,15 @@ function responsive_Modal() { } if ( jQuery('.um-popup-autogrow:visible').length ) { - + jQuery('.um-popup-autogrow:visible').css({'height': ag_height + 'px'}); jQuery('.um-popup-autogrow:visible').mCustomScrollbar({ theme:"dark-3", mouseWheelPixels:500 }).mCustomScrollbar("scrollTo", "bottom",{ scrollInertia:0} ); - + } else if ( jQuery('.um-popup-autogrow2:visible').length ) { - + jQuery('.um-popup-autogrow2:visible').css({'max-height': ag_height + 'px'}); jQuery('.um-popup-autogrow2:visible').mCustomScrollbar({ theme:"dark-3", mouseWheelPixels:500 }); - + } } } @@ -873,7 +894,7 @@ jQuery(function(){ jQuery(".um-search form *").keypress(function(e){ if (e.which == 13) { jQuery('.um-search form').submit(); - return false; + return false; } }); From ac3a0eacfaf3cc3a0b2e2a2c06fbbe901d7ba2dd Mon Sep 17 00:00:00 2001 From: jonfalcon Date: Tue, 16 Feb 2016 16:10:31 -0800 Subject: [PATCH 4/4] Validate username exists on keypress --- assets/css/um-fonticons-fa.css | 16 ++++--- assets/css/um-styles.css | 11 ++++- assets/js/um-functions.js | 60 +++++++++++++++++++++++++- core/um-actions-ajax.php | 77 +++++++++++++++++++++------------- core/um-fields.php | 6 +-- 5 files changed, 130 insertions(+), 40 deletions(-) diff --git a/assets/css/um-fonticons-fa.css b/assets/css/um-fonticons-fa.css index 5e38001b..5577f1a5 100644 --- a/assets/css/um-fonticons-fa.css +++ b/assets/css/um-fonticons-fa.css @@ -784,6 +784,10 @@ .um-faicon-spinner:before { content: "\f110"; } +.um-faicon-spin { + -webkit-animation: um-faicon-spin 2s infinite linear; + animation: um-faicon-spin 2s infinite linear; +} .um-faicon-circle:before { content: "\f111"; } @@ -1532,7 +1536,7 @@ content: "\f20c"; } -@-moz-keyframes spin { +@-moz-keyframes um-faicon-spin { 0% { -moz-transform: rotate(0deg); } @@ -1540,7 +1544,7 @@ -moz-transform: rotate(359deg); } } -@-webkit-keyframes spin { +@-webkit-keyframes um-faicon-spin { 0% { -webkit-transform: rotate(0deg); } @@ -1548,7 +1552,7 @@ -webkit-transform: rotate(359deg); } } -@-o-keyframes spin { +@-o-keyframes um-faicon-spin { 0% { -o-transform: rotate(0deg); } @@ -1556,7 +1560,7 @@ -o-transform: rotate(359deg); } } -@-ms-keyframes spin { +@-ms-keyframes um-faicon-spin { 0% { -ms-transform: rotate(0deg); } @@ -1564,11 +1568,11 @@ -ms-transform: rotate(359deg); } } -@keyframes spin { +@keyframes um-faicon-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(359deg); } -} \ No newline at end of file +} diff --git a/assets/css/um-styles.css b/assets/css/um-styles.css index 6cbcc5bf..a0826f6b 100644 --- a/assets/css/um-styles.css +++ b/assets/css/um-styles.css @@ -753,6 +753,15 @@ small.um-max-filesize span{ } .um-form .um-field .um-field-area input.um-form-field.um-validate-not-matched, -.um-form .um-field .um-field-area input.um-form-field.um-validate-not-matched:focus { +.um-form .um-field .um-field-area input.um-form-field.um-validate-not-matched:focus, +.um-form .um-field .um-field-area input.um-form-field.um-validate-username-exists, +.um-form .um-field .um-field-area input.um-form-field.um-validate-username-exists:focus { border-color: #DB2929 !important; } + +.um-form .um-field .um-field-area input.um-searching-username { + background-image: url('../img/loading.gif'); + background-position: right center; + background-repeat: no-repeat; + background-size: 24px 24px; +} diff --git a/assets/js/um-functions.js b/assets/js/um-functions.js index e202ea69..8cacab19 100644 --- a/assets/js/um-functions.js +++ b/assets/js/um-functions.js @@ -211,11 +211,69 @@ function UM_check_password_matched() { } }); } + +var xhrValidateUsername = false; +function UM_check_username() { + jQuery(document).on('input[data-key=user_login]').on('keyup', function() { + var field = jQuery('input[data-key=user_login]'); + var value = field.val(); + + if(field.parents('.um-field').find('.um-field-error').length) { + var error = field.parents('.um-field').find('.um-field-error'); + } else { + var error = jQuery('
Your username is already taken
'); + } + + // abort previous xhr request + if(xhrValidateUsername) { + xhrValidateUsername.abort(); + } + + if(!value) { + field.removeClass('um-searching-username'); + + return; + } + + field.addClass('um-searching-username'); + + xhrValidateUsername = jQuery.ajax({ + url : um_scripts.ajaxurl, + type : 'post', + data : { + action : 'ultimatemember_check_username_exists', + username : value + }, + complete: function(){ + field.removeClass('um-searching-username'); + }, + success: function(exists){ + if(parseInt(exists) > 0) { + field.removeClass('um-validate-username-unique').addClass('um-validate-username-exists'); + + if(!field.parents('.um-field').find('.um-field-error').length) { + field.parents('.um-field').append(error); + } + + error.show(); + } else { + field.removeClass('um-validate-username-exists').addClass('um-validate-username-unique'); + error.hide(); + } + } + }); + }); +} + jQuery(document).ready(function(){ if(jQuery('input[data-key=user_password],input[data-key=confirm_user_password]').length == 2) { UM_check_password_matched(); } -}) + + if(jQuery('input[data-key=user_login]').length) { + UM_check_username(); + } +}); function UM_hide_menus() { diff --git a/core/um-actions-ajax.php b/core/um-actions-ajax.php index 3fe320df..2d9663b5 100644 --- a/core/um-actions-ajax.php +++ b/core/um-actions-ajax.php @@ -1,24 +1,24 @@ - + - + files->delete_file( $src ); } - + /*** *** @remove profile photo silently ***/ @@ -38,13 +38,13 @@ function ultimatemember_delete_profile_photo(){ global $ultimatemember; extract($_REQUEST); - + if ( !um_current_user_can('edit', $user_id ) ) die( __('You can not edit this user') ); $ultimatemember->files->delete_core_user_photo( $user_id, 'profile_photo' ); } - + /*** *** @remove cover photo silently ***/ @@ -53,13 +53,13 @@ function ultimatemember_delete_cover_photo(){ global $ultimatemember; extract($_REQUEST); - + if ( !um_current_user_can('edit', $user_id ) ) die( __('You can not edit this user') ); $ultimatemember->files->delete_core_user_photo( $user_id, 'cover_photo' ); } - + /*** *** @resampling/crop images ***/ @@ -68,35 +68,35 @@ function ultimatemember_resize_image(){ global $ultimatemember; $output = 0; - + extract($_REQUEST); - + if ( !isset($src) || !isset($coord) ) die( __('Invalid parameters') ); - + $coord_n = substr_count($coord, ","); if ( $coord_n != 3 ) die( __('Invalid coordinates') ); - + $um_is_temp_image = um_is_temp_image( $src ); if ( !$um_is_temp_image ) die( __('Invalid Image file') ); - + $crop = explode(',', $coord ); $crop = array_map('intval', $crop); - + $uri = $ultimatemember->files->resize_image( $um_is_temp_image, $crop ); // If you're updating a user if ( isset( $user_id ) && $user_id > 0 ) { $uri = $ultimatemember->files->new_user_upload( $user_id, $um_is_temp_image, $key ); } - + $output = $uri; - + delete_option( "um_cache_userdata_{$user_id}" ); - + if(is_array($output)){ print_r($output); }else{ echo $output; } die; } - + /*** *** @run an ajax action on the fly ***/ @@ -105,9 +105,9 @@ function ultimatemember_muted_action(){ global $ultimatemember; extract($_REQUEST); - + if ( !um_current_user_can('edit', $user_id ) ) die( __('You can not edit this user') ); - + switch( $hook ) { default: do_action("um_run_ajax_function__{$hook}", $_REQUEST); @@ -115,7 +115,7 @@ } } - + /*** *** @run an ajax pagination on the fly ***/ @@ -124,14 +124,33 @@ function ultimatemember_ajax_paginate(){ global $ultimatemember; extract($_REQUEST); - + ob_start(); - + do_action("um_ajax_load_posts__{$hook}", $args); - + $output = ob_get_contents(); ob_end_clean(); - + die($output); - } \ No newline at end of file + } + + /*** + *** @run check if username exists + ***/ + add_action('wp_ajax_nopriv_ultimatemember_check_username_exists', 'ultimatemember_check_username_exists'); + add_action('wp_ajax_ultimatemember_check_username_exists', 'ultimatemember_check_username_exists'); + function ultimatemember_check_username_exists() { + $username = isset($_REQUEST['username']) ? $_REQUEST['username'] : ''; + $exists = username_exists( $username ); + $exists = apply_filters( 'um_validate_username_exists', $exists, $username ); + + if( $exists ) { + echo 1; + } else { + echo 0; + } + + die(); + } diff --git a/core/um-fields.php b/core/um-fields.php index 41b862ea..104dc46e 100644 --- a/core/um-fields.php +++ b/core/um-fields.php @@ -934,7 +934,7 @@ class UM_Fields { } $type = apply_filters("um_hook_for_field_{$type}", $type ); - + /* Begin by field type */ switch( $type ) { @@ -2109,7 +2109,7 @@ class UM_Fields { } $res = stripslashes( $this->field_value( $key, $default, $data ) ); - + $res = apply_filters("um_view_field_value_{$type}", $res, $data ); $output .= '
'; @@ -2275,7 +2275,7 @@ class UM_Fields { $output .= $this->view_field( $key, $data ); - + } } $output .= '
';