- fixed validation URLs;

- code formatting;
This commit is contained in:
nikitasinelnikov
2020-02-23 23:34:11 +02:00
parent a4e44a32f1
commit bb948b59af
5 changed files with 158 additions and 158 deletions
+2 -16
View File
@@ -286,29 +286,15 @@ if ( ! class_exists( 'um\core\Validation' ) ) {
*
* @return bool
*/
function is_url( $url, $social = false ){
function is_url( $url, $social = false ) {
if ( ! $url ) {
return true;
}
if ( $social ) {
if ( ! filter_var( $url, FILTER_VALIDATE_URL ) && strstr( $url, $social ) ) { // starts with social requested
if ( strstr( $url, $social ) && '' != str_replace( $social, '', $url ) ) {
return true;
} else {
if ( filter_var( $url, FILTER_VALIDATE_URL ) && strstr( $url, $social ) ) {
return true;
} elseif ( preg_match( $this->regex_safe, $url ) ) {
if ( strstr( $url, '.com' ) ) {
return false;
} else {
return true;
}
}
}
} else {
+94 -95
View File
@@ -445,21 +445,21 @@ function um_submit_form_errors_hook_( $args ) {
}
}
if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) {
UM()->form()->add_error($key, sprintf( __( '%s is required.', 'ultimate-member' ), $array['title'] ) );
if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && ! isset( $args[ $key ] ) ) {
UM()->form()->add_error( $key, sprintf( __( '%s is required.', 'ultimate-member' ), $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') ) ) {
UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $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' ) ) ) {
UM()->form()->add_error( $key, sprintf( __( '%s is required.', 'ultimate-member'), $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') ) ) {
UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $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' ) ) ) {
UM()->form()->add_error( $key, sprintf( __( '%s is required.', 'ultimate-member' ), $array['title'] ) );
}
if ( $key == 'role_select' || $key == 'role_radio' ) {
if ( isset( $array['required'] ) && $array['required'] == 1 && ( !isset( $args['role'] ) || empty( $args['role'] ) ) ) {
UM()->form()->add_error('role', __('Please specify account type.','ultimate-member') );
if ( isset( $array['required'] ) && $array['required'] == 1 && ( ! isset( $args['role'] ) || empty( $args['role'] ) ) ) {
UM()->form()->add_error( 'role', __( 'Please specify account type.', 'ultimate-member' ) );
}
}
@@ -499,20 +499,20 @@ function um_submit_form_errors_hook_( $args ) {
if ( isset( $args[ $key ] ) ) {
if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) {
if ( str_word_count( $args[$key], 0, "éèàôù" ) > $array['max_words'] ) {
UM()->form()->add_error($key, sprintf(__('You are only allowed to enter a maximum of %s words','ultimate-member'), $array['max_words']) );
if ( str_word_count( $args[ $key ], 0, "éèàôù" ) > $array['max_words'] ) {
UM()->form()->add_error( $key, sprintf( __( 'You are only allowed to enter a maximum of %s words', 'ultimate-member' ), $array['max_words'] ) );
}
}
if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) {
if ( $args[$key] && strlen( utf8_decode( $args[ $key ] ) ) < $array['min_chars'] ) {
UM()->form()->add_error($key, sprintf(__('Your %s must contain at least %s characters','ultimate-member'), $array['label'], $array['min_chars']) );
if ( $args[ $key ] && strlen( utf8_decode( $args[ $key ] ) ) < $array['min_chars'] ) {
UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain at least %s characters', 'ultimate-member' ), $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'] ) {
UM()->form()->add_error($key, sprintf(__('Your %s must contain less than %s characters','ultimate-member'), $array['label'], $array['max_chars']) );
if ( $args[ $key ] && strlen( utf8_decode( $args[ $key ] ) ) > $array['max_chars'] ) {
UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain less than %s characters', 'ultimate-member' ), $array['label'], $array['max_chars'] ) );
}
}
@@ -520,52 +520,52 @@ function um_submit_form_errors_hook_( $args ) {
if ( $profile_show_html_bio == 1 && $key !== 'description' ) {
if ( isset( $array['html'] ) && $array['html'] == 0 ) {
if ( wp_strip_all_tags( $args[$key] ) != trim( $args[ $key ] ) ) {
if ( wp_strip_all_tags( $args[ $key ] ) != trim( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'You can not use HTML tags here', 'ultimate-member' ) );
}
}
}
if ( isset( $array['force_good_pass'] ) && $array['force_good_pass'] == 1 ) {
if ( ! UM()->validation()->strong_pass( $args[$key] ) ) {
UM()->form()->add_error($key, __('Your password must contain at least one lowercase letter, one capital letter and one number','ultimate-member') );
if ( ! UM()->validation()->strong_pass( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __('Your password must contain at least one lowercase letter, one capital letter and one number', 'ultimate-member' ) );
}
}
if ( isset( $array['force_confirm_pass'] ) && $array['force_confirm_pass'] == 1 ) {
if ( $args[ 'confirm_' . $key] == '' && ! UM()->form()->has_error($key) ) {
UM()->form()->add_error( 'confirm_' . $key , __('Please confirm your password','ultimate-member') );
if ( $args[ 'confirm_' . $key ] == '' && ! UM()->form()->has_error( $key ) ) {
UM()->form()->add_error( 'confirm_' . $key , __( 'Please confirm your password', 'ultimate-member' ) );
}
if ( $args[ 'confirm_' . $key] != $args[$key] && !UM()->form()->has_error($key) ) {
UM()->form()->add_error( 'confirm_' . $key , __('Your passwords do not match','ultimate-member') );
if ( $args[ 'confirm_' . $key ] != $args[$key] && !UM()->form()->has_error( $key ) ) {
UM()->form()->add_error( 'confirm_' . $key , __( 'Your passwords do not match', 'ultimate-member' ) );
}
}
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'] ) ) {
UM()->form()->add_error($key, sprintf(__('Please select at least %s choices','ultimate-member'), $array['min_selections'] ) );
if ( ( ! isset( $args[ $key ] ) ) || ( isset( $args[ $key ] ) && is_array( $args[ $key ] ) && count( $args[ $key ] ) < $array['min_selections'] ) ) {
UM()->form()->add_error($key, sprintf( __( 'Please select at least %s choices', 'ultimate-member' ), $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'] ) {
UM()->form()->add_error($key, sprintf(__('You can only select up to %s choices','ultimate-member'), $array['max_selections'] ) );
if ( isset( $args[ $key ] ) && is_array( $args[ $key ] ) && count( $args[ $key ] ) > $array['max_selections'] ) {
UM()->form()->add_error( $key, sprintf( __( 'You can only select up to %s choices', 'ultimate-member' ), $array['max_selections'] ) );
}
}
if ( isset( $array['min'] ) && is_numeric( $args[ $key ] ) ) {
if ( isset( $args[ $key ] ) && $args[ $key ] < $array['min'] ) {
UM()->form()->add_error( $key, sprintf(__('Minimum number limit is %s','ultimate-member'), $array['min'] ) );
UM()->form()->add_error( $key, sprintf( __( 'Minimum number limit is %s', 'ultimate-member' ), $array['min'] ) );
}
}
if ( isset( $array['max'] ) && is_numeric( $args[ $key ] ) ) {
if ( isset( $args[ $key ] ) && $args[ $key ] > $array['max'] ) {
UM()->form()->add_error( $key, sprintf(__('Maximum number limit is %s','ultimate-member'), $array['max'] ) );
UM()->form()->add_error( $key, sprintf( __( 'Maximum number limit is %s', 'ultimate-member' ), $array['max'] ) );
}
}
if ( isset( $array['validate'] ) && !empty( $array['validate'] ) ) {
if ( ! empty( $array['validate'] ) ) {
switch( $array['validate'] ) {
@@ -596,74 +596,75 @@ function um_submit_form_errors_hook_( $args ) {
break;
case 'numeric':
if ( $args[$key] && !is_numeric( $args[$key] ) ) {
UM()->form()->add_error($key, __('Please enter numbers only in this field','ultimate-member') );
if ( $args[ $key ] && ! is_numeric( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Please enter numbers only in this field', 'ultimate-member' ) );
}
break;
case 'phone_number':
if ( ! UM()->validation()->is_phone_number( $args[$key] ) ) {
UM()->form()->add_error($key, __('Please enter a valid phone number','ultimate-member') );
if ( ! UM()->validation()->is_phone_number( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Please enter a valid phone number', 'ultimate-member' ) );
}
break;
case 'youtube_url':
if ( ! UM()->validation()->is_url( $args[$key], 'youtube.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'youtube.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
}
break;
case 'soundcloud_url':
if ( ! UM()->validation()->is_url( $args[$key], 'soundcloud.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'soundcloud.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
}
break;
case 'facebook_url':
if ( ! UM()->validation()->is_url( $args[$key], 'facebook.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'facebook.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
}
break;
case 'twitter_url':
if ( ! UM()->validation()->is_url( $args[$key], 'twitter.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'twitter.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
}
break;
case 'instagram_url':
if ( ! UM()->validation()->is_url( $args[$key], 'instagram.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'instagram.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s profile URL', 'ultimate-member' ), $array['label'] ) );
}
break;
case 'google_url':
if ( ! UM()->validation()->is_url( $args[$key], 'plus.google.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'plus.google.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
}
break;
case 'linkedin_url':
if ( ! UM()->validation()->is_url( $args[$key], 'linkedin.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'linkedin.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
}
break;
case 'vk_url':
if ( ! UM()->validation()->is_url( $args[$key], 'vk.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'vk.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
}
break;
case 'url':
if ( ! UM()->validation()->is_url( $args[$key] ) ) {
UM()->form()->add_error($key, __('Please enter a valid URL','ultimate-member') );
if ( ! UM()->validation()->is_url( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Please enter a valid URL', 'ultimate-member' ) );
}
break;
case 'skype':
if ( ! UM()->validation()->is_url( $args[$key], 'skype.com' ) ) {
UM()->form()->add_error($key, sprintf(__('Please enter a valid %s username or profile URL','ultimate-member'), $array['label'] ) );
if ( ! UM()->validation()->is_url( $args[ $key ], 'skype.com' ) ) {
UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
}
break;
@@ -675,7 +676,7 @@ function um_submit_form_errors_hook_( $args ) {
UM()->form()->add_error( $key, __( 'Your username is already taken', 'ultimate-member' ) );
} elseif ( is_email( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Username cannot be an email', 'ultimate-member' ) );
} elseif ( ! UM()->validation()->safe_username( $args[$key] ) ) {
} elseif ( ! UM()->validation()->safe_username( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Your username contains invalid characters', 'ultimate-member' ) );
}
@@ -683,14 +684,14 @@ function um_submit_form_errors_hook_( $args ) {
case 'unique_username_or_email':
if ( $args[$key] == '' ) {
UM()->form()->add_error($key, __('You must provide a username','ultimate-member') );
} else if ( $mode == 'register' && username_exists( sanitize_user( $args[$key] ) ) ) {
UM()->form()->add_error($key, __('Your username is already taken','ultimate-member') );
} else if ( $mode == 'register' && email_exists( $args[$key] ) ) {
UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') );
} else if ( ! UM()->validation()->safe_username( $args[$key] ) ) {
UM()->form()->add_error($key, __('Your username contains invalid characters','ultimate-member') );
if ( $args[ $key ] == '' ) {
UM()->form()->add_error( $key, __( 'You must provide a username', 'ultimate-member' ) );
} elseif ( $mode == 'register' && username_exists( sanitize_user( $args[ $key ] ) ) ) {
UM()->form()->add_error( $key, __( 'Your username is already taken', 'ultimate-member' ) );
} elseif ( $mode == 'register' && email_exists( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'This email is already linked to an existing account', 'ultimate-member' ) );
} elseif ( ! UM()->validation()->safe_username( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Your username contains invalid characters', 'ultimate-member' ) );
}
break;
@@ -699,43 +700,42 @@ function um_submit_form_errors_hook_( $args ) {
$args[ $key ] = trim( $args[ $key ] );
if ( in_array( $key, array('user_email') ) ) {
if ( in_array( $key, array( 'user_email' ) ) ) {
if( ! isset( $args['user_id'] ) ){
if ( ! isset( $args['user_id'] ) ){
$args['user_id'] = um_get_requested_user();
}
$email_exists = email_exists( $args[ $key ] );
if ( $args[ $key ] == '' && in_array( $key, array('user_email') ) ) {
UM()->form()->add_error( $key, __('You must provide your email','ultimate-member') );
} else if ( in_array( $mode, array('register') ) && $email_exists ) {
UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') );
} else if ( in_array( $mode, array('profile') ) && $email_exists && $email_exists != $args['user_id'] ) {
UM()->form()->add_error( $key, __('This email is already linked to an existing account','ultimate-member') );
} else if ( !is_email( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __('This is not a valid email','ultimate-member') );
} else if ( ! UM()->validation()->safe_username( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __('Your email contains invalid characters','ultimate-member') );
if ( $args[ $key ] == '' && in_array( $key, array( 'user_email' ) ) ) {
UM()->form()->add_error( $key, __( 'You must provide your email', 'ultimate-member' ) );
} elseif ( in_array( $mode, array( 'register' ) ) && $email_exists ) {
UM()->form()->add_error( $key, __( 'This email is already linked to an existing account', 'ultimate-member' ) );
} elseif ( in_array( $mode, array( 'profile' ) ) && $email_exists && $email_exists != $args['user_id'] ) {
UM()->form()->add_error( $key, __( 'This email is already linked to an existing account', 'ultimate-member' ) );
} elseif ( !is_email( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'This is not a valid email', 'ultimate-member') );
} elseif ( ! UM()->validation()->safe_username( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'Your email contains invalid characters', 'ultimate-member' ) );
}
} else {
if ( $args[ $key ] != '' && !is_email( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __('This is not a valid email','ultimate-member') );
} else if ( $args[ $key ] != '' && email_exists( $args[ $key ] ) ) {
UM()->form()->add_error($key, __('This email is already linked to an existing account','ultimate-member') );
} else if ( $args[ $key ] != '' ) {
$users = get_users('meta_value='.$args[ $key ]);
if ( $args[ $key ] != '' && ! is_email( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'This is not a valid email', 'ultimate-member' ) );
} elseif ( $args[ $key ] != '' && email_exists( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'This email is already linked to an existing account', 'ultimate-member' ) );
} elseif ( $args[ $key ] != '' ) {
$users = get_users( 'meta_value=' . $args[ $key ] );
foreach ( $users as $user ) {
if( $user->ID != $args['user_id'] ){
UM()->form()->add_error( $key, __('This email is already linked to an existing account','ultimate-member') );
if ( $user->ID != $args['user_id'] ) {
UM()->form()->add_error( $key, __( 'This email is already linked to an existing account', 'ultimate-member' ) );
}
}
}
}
@@ -746,28 +746,27 @@ function um_submit_form_errors_hook_( $args ) {
$args[ $key ] = trim( $args[ $key ] );
if ( $args[ $key ] != '' && !is_email( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __('This is not a valid email','ultimate-member') );
}
if ( $args[ $key ] != '' && ! is_email( $args[ $key ] ) ) {
UM()->form()->add_error( $key, __( 'This is not a valid email', 'ultimate-member' ) );
}
break;
case 'unique_value':
if ( $args[$key] != '' ) {
if ( $args[ $key ] != '' ) {
$args_unique_meta = array(
'meta_key' => $key,
'meta_value' => $args[ $key ],
'compare' => '=',
'exclude' => array( $args['user_id'] ),
'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 ) {
UM()->form()->add_error( $key , __('You must provide a unique value','ultimate-member') );
UM()->form()->add_error( $key , __( 'You must provide a unique value', 'ultimate-member' ) );
}
}
break;
@@ -788,8 +787,8 @@ function um_submit_form_errors_hook_( $args ) {
if ( $args[ $key ] != '' ) {
if ( ! ctype_lower( str_replace(' ', '',$args[$key] ) ) ){
UM()->form()->add_error( $key , __('You must provide lowercase letters.','ultimate-member') );
if ( ! ctype_lower( str_replace(' ', '', $args[ $key ] ) ) ) {
UM()->form()->add_error( $key , __( 'You must provide lowercase letters.', 'ultimate-member' ) );
}
}