diff --git a/includes/core/class-form.php b/includes/core/class-form.php
index 5ae5f373..7a55db89 100644
--- a/includes/core/class-form.php
+++ b/includes/core/class-form.php
@@ -456,6 +456,13 @@ if ( ! class_exists( 'um\core\Form' ) ) {
// The '_um_last_login' cannot be updated through UM form.
$cf_metakeys = array_values( array_diff( $cf_metakeys, array( 'role_select', 'role_radio', 'role', '_um_last_login' ) ) );
+ // Column names from wp_users table.
+ $cf_metakeys = array_values( array_diff( $cf_metakeys, UM()->user()->update_user_keys ) );
+ // Remove restricted fields when edit profile.
+ if ( 'profile' === $this->form_data['mode'] ) {
+ $cf_metakeys = array_values( array_diff( $cf_metakeys, UM()->fields()->get_restricted_fields_for_edit() ) );
+ }
+ // Add required usermeta for register.
if ( 'register' === $this->form_data['mode'] ) {
$cf_metakeys[] = 'submitted';
}
@@ -659,6 +666,7 @@ if ( ! class_exists( 'um\core\Form' ) ) {
var_dump( '------------------------------------------------------------' );
var_dump( $all_cf_metakeys );
var_dump( $cf_metakeys );
+ var_dump( UM()->form()->errors );
exit;
}
/* Continue based on form mode - store data. */
diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php
index 54e180ba..ab08f406 100644
--- a/includes/core/um-actions-form.php
+++ b/includes/core/um-actions-form.php
@@ -67,34 +67,40 @@ function um_submit_form_errors_hook__blockedips() {
}
add_action( 'um_submit_form_errors_hook__blockedips', 'um_submit_form_errors_hook__blockedips' );
-
/**
* Error handling: blocked words during sign up
*
- * @param $args
+ * @todo change the hook after checking that conditions inside this callback can be run only while registration.
+ *
+ * @param array $submitted_data
+ * @param array $form_data
*/
-function um_submit_form_errors_hook__blockedwords( $args ) {
+function um_submit_form_errors_hook__blockedwords( $submitted_data, $form_data ) {
$words = UM()->options()->get( 'blocked_words' );
if ( empty( $words ) ) {
return;
}
- $fields = unserialize( $args['custom_fields'] );
+ $fields = maybe_unserialize( $form_data['custom_fields'] );
+ if ( empty( $fields ) || ! is_array( $fields ) ) {
+ return;
+ }
$words = strtolower( $words );
$words = array_map( 'rtrim', explode( "\n", $words ) );
- if ( ! empty( $fields ) && is_array( $fields ) ) {
- foreach ( $fields as $key => $array ) {
- if ( isset( $array['validate'] ) && in_array( $array['validate'], array( 'unique_username', 'unique_email', 'unique_username_or_email' ) ) ) {
- if ( ! UM()->form()->has_error( $key ) && isset( $args[ $key ] ) && in_array( strtolower( $args[ $key ] ), $words ) ) {
- UM()->form()->add_error( $key, __( 'You are not allowed to use this word as your username.', 'ultimate-member' ) );
- }
+ foreach ( $fields as $key => $array ) {
+ if ( isset( $array['validate'] ) && in_array( $array['validate'], array( 'unique_username', 'unique_email', 'unique_username_or_email' ), true ) ) {
+ if ( UM()->form()->has_error( $key ) ) {
+ continue;
+ }
+
+ if ( array_key_exists( $key, $submitted_data ) && in_array( strtolower( $submitted_data[ $key ] ), $words, true ) ) {
+ UM()->form()->add_error( $key, __( 'You are not allowed to use this word as your username.', 'ultimate-member' ) );
}
}
}
}
-add_action( 'um_submit_form_errors_hook__blockedwords', 'um_submit_form_errors_hook__blockedwords', 10 );
-
+add_action( 'um_submit_form_errors_hook__blockedwords', 'um_submit_form_errors_hook__blockedwords', 10, 2 );
/**
* UM login|register|profile form error handling.
@@ -117,7 +123,7 @@ function um_submit_form_errors_hook( $submitted_data, $form_data ) {
* @param {array} $submitted_data $_POST Submission array.
* @param {array} $form_data UM form data. Since 2.6.7
*
- * @example
Make any common validation action here.
+ * @example Make any common validation action when login, registation or profile form is submitted.
* function my_submit_form_errors_hook__blockedips( $post, $form_data ) {
* // your code here
* }
@@ -136,7 +142,7 @@ function um_submit_form_errors_hook( $submitted_data, $form_data ) {
* @param {array} $submitted_data $_POST Submission array.
* @param {array} $form_data UM form data. Since 2.6.7
*
- * @example Make any common validation action here.
+ * @example Make any common validation action when login, registation or profile form is submitted.
* function my_submit_form_errors_hook__blockedemails( $post, $form_data ) {
* // your code here
* }
@@ -157,7 +163,7 @@ function um_submit_form_errors_hook( $submitted_data, $form_data ) {
* @param {array} $submitted_data $_POST Submission array.
* @param {array} $form_data UM form data. Since 2.6.7
*
- * @example Make any common validation action here.
+ * @example Make any validation action when login form is submitted.
* function my_submit_form_errors_hook_login( $post, $form_data ) {
* // your code here
* }
@@ -176,97 +182,92 @@ function um_submit_form_errors_hook( $submitted_data, $form_data ) {
* @param {array} $submitted_data $_POST Submission array.
* @param {array} $form_data UM form data. Since 2.6.7
*
- * @example Make any common validation action here.
+ * @example Make any validation action when login form is submitted.
* function my_submit_form_errors_hook_logincheck( $post, $form_data ) {
* // your code here
* }
* add_action( 'um_submit_form_errors_hook_logincheck', 'my_submit_form_errors_hook_logincheck', 10, 2 );
*/
do_action( 'um_submit_form_errors_hook_logincheck', $submitted_data, $form_data );
- // ------ Reviewed. --------- //
} else {
if ( 'register' === $mode ) {
/**
- * UM hook
+ * Fires for registration form validation when it has been submitted.
*
- * @type action
- * @title um_submit_form_errors_hook__registration
- * @description Submit registration form validation
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Form Arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_submit_form_errors_hook__registration', 'function_name', 10, 1 );
- * @example
- * Callback name -> Excerpt):
+ * 10 - `um_submit_form_errors_hook__registration()` Native registration validation handlers.
+ *
+ * @since 1.3.x
+ * @hook um_submit_form_errors_hook__registration
+ *
+ * @param {array} $submitted_data $_POST Submission array.
+ * @param {array} $form_data UM form data. Since 2.6.7
+ *
+ * @example Make any validation action when registration form submitted.
+ * function my_submit_form_errors_hook__registration( $submitted_data, $form_data ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_submit_form_errors_hook__registration', 'my_submit_form_errors_hook__registration', 10, 2 );
*/
do_action( 'um_submit_form_errors_hook__registration', $submitted_data, $form_data );
} elseif ( 'profile' === $mode ) {
/**
- * UM hook
+ * Fires for profile form validation when it has been submitted.
*
- * @type action
- * @title um_submit_form_errors_hook__registration
- * @description Submit registration form validation
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Form Arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_submit_form_errors_hook__registration', 'function_name', 10, 1 );
- * @example
- * Callback name -> Excerpt):
+ * 1 - `um_profile_validate_nonce()` Validate nonce.
+ *
+ * @since 2.0
+ * @hook um_submit_form_errors_hook__profile
+ *
+ * @param {array} $submitted_data $_POST Submission array.
+ * @param {array} $form_data UM form data. Since 2.6.7
+ *
+ * @example Make any validation action when profile form submitted.
+ * function my_submit_form_errors_hook__profile( $submitted_data, $form_data ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_submit_form_errors_hook__profile', 'my_submit_form_errors_hook__profile', 10, 2 );
*/
do_action( 'um_submit_form_errors_hook__profile', $submitted_data, $form_data );
}
/**
- * UM hook
+ * Fires for registration and profile forms validation when it has been submitted.
*
- * @type action
- * @title um_submit_form_errors_hook__blockedwords
- * @description Submit form validation
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Form Arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_submit_form_errors_hook__blockedwords', 'function_name', 10, 1 );
- * @example
- * Callback name -> Excerpt):
+ * 10 - `um_submit_form_errors_hook__blockedwords()` Validate username and email from blocked words.
+ *
+ * @since 1.3.x
+ * @hook um_submit_form_errors_hook__blockedwords
+ *
+ * @param {array} $submitted_data $_POST Submission array.
+ * @param {array} $form_data UM form data. Since 2.6.7
+ *
+ * @example Make any validation action when registration or profile form submitted.
+ * function my_submit_form_errors_hook__blockedwords( $submitted_data, $form_data ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_submit_form_errors_hook__blockedwords', 'my_submit_form_errors_hook__blockedwords', 10, 2 );
*/
do_action( 'um_submit_form_errors_hook__blockedwords', $submitted_data, $form_data );
/**
- * UM hook
+ * Fires for registration and profile forms validation when it has been submitted.
*
- * @type action
- * @title um_submit_form_errors_hook_
- * @description Submit form validation
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Form Arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_submit_form_errors_hook_', 'function_name', 10, 1 );
- * @example
- * Callback name -> Excerpt):
+ * 10 - `um_submit_form_errors_hook_()` Run field validations.
+ *
+ * @since 1.3.x
+ * @hook um_submit_form_errors_hook_
+ *
+ * @param {array} $submitted_data $_POST Submission array.
+ * @param {array} $form_data UM form data. Since 2.6.7
+ *
+ * @example Make any validation action when registration or profile form submitted.
+ * function my_submit_form_errors_hook( $submitted_data, $form_data ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_submit_form_errors_hook_', 'my_submit_form_errors_hook', 10, 2 );
*/
do_action( 'um_submit_form_errors_hook_', $submitted_data, $form_data );
}
@@ -279,12 +280,12 @@ add_action( 'um_submit_form_errors_hook', 'um_submit_form_errors_hook', 10, 2 );
* @staticvar int $counter
* @param array $condition
* @param array $fields
- * @param array $args
+ * @param array $submitted_data
* @param boolean $reset
* @return boolean
* @throws Exception
*/
-function um_check_conditions_on_submit( $condition, $fields, $args, $reset = false ) {
+function um_check_conditions_on_submit( $condition, $fields, $submitted_data, $reset = false ) {
static $counter = 0;
if ( $reset ) {
$counter = 0;
@@ -293,7 +294,7 @@ function um_check_conditions_on_submit( $condition, $fields, $args, $reset = fal
list( $visibility, $parent_key, $op, $parent_value ) = $condition;
- if ( ! isset( $args[ $parent_key ] ) ) {
+ if ( ! isset( $submitted_data[ $parent_key ] ) ) {
$continue = true;
return $continue;
}
@@ -301,7 +302,7 @@ function um_check_conditions_on_submit( $condition, $fields, $args, $reset = fal
if ( ! empty( $fields[ $parent_key ]['conditions'] ) ) {
foreach ( $fields[ $parent_key ]['conditions'] as $parent_condition ) {
if ( 64 > $counter++ ) {
- $continue = um_check_conditions_on_submit( $parent_condition, $fields, $args );
+ $continue = um_check_conditions_on_submit( $parent_condition, $fields, $submitted_data );
} else {
throw new Exception( 'Endless recursion in the function ' . __FUNCTION__, 512 );
}
@@ -311,7 +312,7 @@ function um_check_conditions_on_submit( $condition, $fields, $args, $reset = fal
}
}
- $cond_value = ( $fields[ $parent_key ]['type'] == 'radio' ) ? $args[ $parent_key ][0] : $args[ $parent_key ];
+ $cond_value = ( $fields[ $parent_key ]['type'] == 'radio' ) ? $submitted_data[ $parent_key ][0] : $submitted_data[ $parent_key ];
if ( $visibility == 'hide' ) {
if ( $op == 'empty' ) {
@@ -384,540 +385,539 @@ function um_check_conditions_on_submit( $condition, $fields, $args, $reset = fal
return $continue;
}
-
/**
* Error processing hook : standard
*
- * @param $args
+ * @param array $submitted_data
+ * @param array $form_data
*/
-function um_submit_form_errors_hook_( $args ) {
- $form_id = $args['form_id'];
- $mode = $args['mode'];
- $fields = unserialize( $args['custom_fields'] );
+function um_submit_form_errors_hook_( $submitted_data, $form_data ) {
+ $form_id = $form_data['form_id'];
+ $mode = $form_data['mode'];
- $um_profile_photo = um_profile('profile_photo');
- if ( get_post_meta( $form_id, '_um_profile_photo_required', true ) && ( empty( $args['profile_photo'] ) && empty( $um_profile_photo ) ) ) {
- UM()->form()->add_error('profile_photo', __( 'Profile Photo is required.', 'ultimate-member' ) );
+ $fields = maybe_unserialize( $form_data['custom_fields'] );
+ if ( empty( $fields ) || ! is_array( $fields ) ) {
+ return;
}
- if ( ! empty( $fields ) ) {
- $can_edit = false;
- $current_user_roles = array();
- if ( is_user_logged_in() ) {
- if ( array_key_exists( 'user_id', $args ) ) {
- $can_edit = UM()->roles()->um_current_user_can( 'edit', $args['user_id'] );
- }
+ $um_profile_photo = um_profile( 'profile_photo' );
+ if ( empty( $submitted_data['profile_photo'] ) && empty( $um_profile_photo ) && get_post_meta( $form_id, '_um_profile_photo_required', true ) ) {
+ UM()->form()->add_error( 'profile_photo', __( 'Profile Photo is required.', 'ultimate-member' ) );
+ }
- um_fetch_user( get_current_user_id() );
- $current_user_roles = um_user( 'roles' );
- um_reset_user();
+ $can_edit = false;
+ $current_user_roles = array();
+ if ( is_user_logged_in() ) {
+ if ( array_key_exists( 'user_id', $submitted_data ) ) {
+ $can_edit = UM()->roles()->um_current_user_can( 'edit', $submitted_data['user_id'] );
}
- foreach ( $fields as $key => $array ) {
+ um_fetch_user( get_current_user_id() );
+ $current_user_roles = um_user( 'roles' );
+ um_reset_user();
+ }
- if ( 'profile' === $mode ) {
- $restricted_fields = UM()->fields()->get_restricted_fields_for_edit();
- if ( is_array( $restricted_fields ) && in_array( $key, $restricted_fields ) ) {
- continue;
- }
- }
+ foreach ( $fields as $key => $array ) {
- $can_view = true;
- if ( isset( $array['public'] ) && 'register' !== $mode ) {
-
- switch ( $array['public'] ) {
- case '1': // Everyone
- break;
- case '2': // Members
- if ( ! is_user_logged_in() ) {
- $can_view = false;
- }
- break;
- case '-1': // Only visible to profile owner and admins
- if ( ! is_user_logged_in() ) {
- $can_view = false;
- } elseif ( $args['user_id'] != get_current_user_id() && ! $can_edit ) {
- $can_view = false;
- }
- break;
- case '-2': // Only specific member roles
- if ( ! is_user_logged_in() ) {
- $can_view = false;
- } elseif ( ! empty( $array['roles'] ) && count( array_intersect( $current_user_roles, $array['roles'] ) ) <= 0 ) {
- $can_view = false;
- }
- break;
- case '-3': // Only visible to profile owner and specific roles
- if ( ! is_user_logged_in() ) {
- $can_view = false;
- } elseif ( $args['user_id'] != get_current_user_id() && ! empty( $array['roles'] ) && count( array_intersect( $current_user_roles, $array['roles'] ) ) <= 0 ) {
- $can_view = false;
- }
- break;
- default:
- $can_view = apply_filters( 'um_can_view_field_custom', $can_view, $array );
- break;
- }
-
- }
-
- $can_view = apply_filters( 'um_can_view_field', $can_view, $array );
-
- if ( ! $can_view ) {
+ if ( 'profile' === $mode ) {
+ $restricted_fields = UM()->fields()->get_restricted_fields_for_edit();
+ if ( is_array( $restricted_fields ) && in_array( $key, $restricted_fields, true ) ) {
continue;
}
+ }
- /**
- * UM hook
- *
- * @type filter
- * @title um_get_custom_field_array
- * @description Extend custom field data on submit form error
- * @input_vars
- * [{"var":"$array","type":"array","desc":"Field data"},
- * {"var":"$fields","type":"array","desc":"All fields"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- *
- */
- $array = apply_filters( 'um_get_custom_field_array', $array, $fields );
+ $can_view = true;
+ if ( isset( $array['public'] ) && 'register' !== $mode ) {
- if ( ! empty( $array['conditions'] ) ) {
- try {
- foreach ( $array['conditions'] as $condition ) {
- $continue = um_check_conditions_on_submit( $condition, $fields, $args, true );
- if ( $continue === true ) {
- continue 2;
- }
+ switch ( $array['public'] ) {
+ case '1': // Everyone
+ break;
+ case '2': // Members
+ if ( ! is_user_logged_in() ) {
+ $can_view = false;
}
- } catch ( Exception $e ) {
- UM()->form()->add_error( $key, sprintf( __( '%s - wrong conditions.', 'ultimate-member' ), $array['title'] ) );
- $notice = '' . sprintf( __( '%s - wrong conditions.', 'ultimate-member' ), $array['title'] ) . '
';
- add_action( 'um_after_profile_fields', function() use ( $notice ) {
- echo $notice;
- }, 900 );
+ break;
+ case '-1': // Only visible to profile owner and admins
+ if ( ! is_user_logged_in() ) {
+ $can_view = false;
+ } elseif ( $submitted_data['user_id'] != get_current_user_id() && ! $can_edit ) {
+ $can_view = false;
+ }
+ break;
+ case '-2': // Only specific member roles
+ if ( ! is_user_logged_in() ) {
+ $can_view = false;
+ } elseif ( ! empty( $array['roles'] ) && count( array_intersect( $current_user_roles, $array['roles'] ) ) <= 0 ) {
+ $can_view = false;
+ }
+ break;
+ case '-3': // Only visible to profile owner and specific roles
+ if ( ! is_user_logged_in() ) {
+ $can_view = false;
+ } elseif ( $submitted_data['user_id'] != get_current_user_id() && ! empty( $array['roles'] ) && count( array_intersect( $current_user_roles, $array['roles'] ) ) <= 0 ) {
+ $can_view = false;
+ }
+ break;
+ default:
+ $can_view = apply_filters( 'um_can_view_field_custom', $can_view, $array );
+ break;
+ }
+ }
+
+ $can_view = apply_filters( 'um_can_view_field', $can_view, $array );
+
+ if ( ! $can_view ) {
+ continue;
+ }
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_get_custom_field_array
+ * @description Extend custom field data on submit form error
+ * @input_vars
+ * [{"var":"$array","type":"array","desc":"Field data"},
+ * {"var":"$fields","type":"array","desc":"All fields"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $array = apply_filters( 'um_get_custom_field_array', $array, $fields );
+
+ if ( ! empty( $array['conditions'] ) ) {
+ try {
+ foreach ( $array['conditions'] as $condition ) {
+ $continue = um_check_conditions_on_submit( $condition, $fields, $submitted_data, true );
+ if ( $continue === true ) {
+ continue 2;
+ }
+ }
+ } catch ( Exception $e ) {
+ UM()->form()->add_error( $key, sprintf( __( '%s - wrong conditions.', 'ultimate-member' ), $array['title'] ) );
+ $notice = '' . sprintf( __( '%s - wrong conditions.', 'ultimate-member' ), $array['title'] ) . '
';
+ add_action( 'um_after_profile_fields', function() use ( $notice ) {
+ echo $notice;
+ }, 900 );
+ }
+ }
+
+ if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && ! isset( $submitted_data[ $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( $submitted_data[ $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( $submitted_data[ $key ] ) && ! in_array( $key, array( 'role_radio', 'role_select' ) ) ) {
+ UM()->form()->add_error( $key, sprintf( __( '%s is required.', 'ultimate-member' ), $array['title'] ) );
+ }
+
+ /* WordPress uses the default user role if the role wasn't chosen in the registration form. That is why we should use submitted data to validate fields Roles (Radio) and Roles (Dropdown). */
+ if ( in_array( $key, array( 'role_radio', 'role_select' ) ) && isset( $array['required'] ) && $array['required'] == 1 && empty( UM()->form()->post_form['submitted']['role'] ) ) {
+ UM()->form()->add_error( 'role', __( 'Please specify account type.', 'ultimate-member' ) );
+ UM()->form()->post_form[ $key ] = '';
+ }
+
+ /**
+ * UM hook
+ *
+ * @type action
+ * @title um_add_error_on_form_submit_validation
+ * @description Submit form validation
+ * @input_vars
+ * [{"var":"$field","type":"array","desc":"Field Data"},
+ * {"var":"$key","type":"string","desc":"Field Key"},
+ * {"var":"$args","type":"array","desc":"Form Arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_action( 'um_add_error_on_form_submit_validation', 'function_name', 10, 3 );
+ * @example
+ *
+ */
+ do_action( 'um_add_error_on_form_submit_validation', $array, $key, $submitted_data );
+
+ if ( ! empty( $array['required'] ) ) {
+ if ( ! isset( $submitted_data[ $key ] ) || $submitted_data[ $key ] == '' || $submitted_data[ $key ] == 'empty_file' ) {
+ if ( empty( $array['label'] ) ) {
+ UM()->form()->add_error( $key, __( 'This field is required', 'ultimate-member' ) );
+ } else {
+ UM()->form()->add_error( $key, sprintf( __( '%s is required', 'ultimate-member' ), $array['label'] ) );
}
}
+ }
- 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( $submitted_data[ $key ] ) ) {
+ continue;
+ }
+
+ if ( isset( $array['max_words'] ) && $array['max_words'] > 0 ) {
+ if ( str_word_count( $submitted_data[ $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['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'] ) );
- }
-
- /* WordPress uses the default user role if the role wasn't chosen in the registration form. That is why we should use submitted data to validate fields Roles (Radio) and Roles (Dropdown). */
- if ( in_array( $key, array( 'role_radio', 'role_select' ) ) && isset( $array['required'] ) && $array['required'] == 1 && empty( UM()->form()->post_form['submitted']['role'] ) ) {
- UM()->form()->add_error( 'role', __( 'Please specify account type.', 'ultimate-member' ) );
- UM()->form()->post_form[ $key ] = '';
- }
-
- /**
- * UM hook
- *
- * @type action
- * @title um_add_error_on_form_submit_validation
- * @description Submit form validation
- * @input_vars
- * [{"var":"$field","type":"array","desc":"Field Data"},
- * {"var":"$key","type":"string","desc":"Field Key"},
- * {"var":"$args","type":"array","desc":"Form Arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_add_error_on_form_submit_validation', 'function_name', 10, 3 );
- * @example
- *
- */
- do_action( 'um_add_error_on_form_submit_validation', $array, $key, $args );
-
- if ( ! empty( $array['required'] ) ) {
- if ( ! isset( $args[ $key ] ) || $args[ $key ] == '' || $args[ $key ] == 'empty_file' ) {
- if ( empty( $array['label'] ) ) {
- UM()->form()->add_error( $key, __( 'This field is required', 'ultimate-member' ) );
- } else {
- UM()->form()->add_error( $key, sprintf( __( '%s is required', 'ultimate-member' ), $array['label'] ) );
- }
+ if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) {
+ if ( $submitted_data[ $key ] && mb_strlen( $submitted_data[ $key ] ) < $array['min_chars'] ) {
+ if ( empty( $array['label'] ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'This field must contain at least %s characters', 'ultimate-member' ), $array['min_chars'] ) );
+ } else {
+ UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain at least %s characters', 'ultimate-member' ), $array['label'], $array['min_chars'] ) );
}
}
+ }
- if ( isset( $args[ $key ] ) ) {
+ if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) {
+ if ( $submitted_data[ $key ] && mb_strlen( $submitted_data[ $key ] ) > $array['max_chars'] ) {
+ if ( empty( $array['label'] ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'This field must contain less than %s characters', 'ultimate-member' ), $array['max_chars'] ) );
+ } else {
+ UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain less than %s characters', 'ultimate-member' ), $array['label'], $array['max_chars'] ) );
+ }
+ }
+ }
- 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 ( isset( $array['type'] ) && $array['type'] == 'textarea' && UM()->profile()->get_show_bio_key( $submitted_data ) !== $key ) {
+ if ( ! isset( $array['html'] ) || $array['html'] == 0 ) {
+ if ( wp_strip_all_tags( $submitted_data[ $key ] ) != trim( $submitted_data[ $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'] && ! empty( $submitted_data['user_password'] ) ) {
+ if ( isset( $submitted_data['user_login'] ) && strpos( strtolower( $submitted_data['user_login'] ), strtolower( $submitted_data['user_password'] ) ) > -1 ) {
+ UM()->form()->add_error( 'user_password', __( 'Your password cannot contain the part of your username', 'ultimate-member' ));
+ }
+
+ if ( isset( $submitted_data['user_email'] ) && strpos( strtolower( $submitted_data['user_email'] ), strtolower( $submitted_data['user_password'] ) ) > -1 ) {
+ UM()->form()->add_error( 'user_password', __( 'Your password cannot contain the part of your email address', 'ultimate-member' ));
+ }
+
+ if ( ! UM()->validation()->strong_pass( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'Your password must contain at least one lowercase letter, one capital letter and one number', 'ultimate-member' ) );
+ }
+ }
+
+ if ( ! empty( $array['force_confirm_pass'] ) ) {
+ if ( ! array_key_exists( 'confirm_' . $key, $submitted_data ) && ! UM()->form()->has_error( $key ) ) {
+ UM()->form()->add_error( 'confirm_' . $key, __( 'Please confirm your password', 'ultimate-member' ) );
+ } else {
+ if ( '' === $submitted_data[ 'confirm_' . $key ] && ! UM()->form()->has_error( $key ) ) {
+ UM()->form()->add_error( 'confirm_' . $key, __( 'Please confirm your password', 'ultimate-member' ) );
+ }
+ if ( $submitted_data[ 'confirm_' . $key ] !== $submitted_data[ $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( $submitted_data[ $key ] ) ) || ( isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] ) && count( $submitted_data[ $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( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] ) && count( $submitted_data[ $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( $submitted_data[ $key ] ) ) {
+ if ( isset( $submitted_data[ $key ] ) && $submitted_data[ $key ] < $array['min'] ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Minimum number limit is %s', 'ultimate-member' ), $array['min'] ) );
+ }
+ }
+
+ if ( isset( $array['max'] ) && is_numeric( $submitted_data[ $key ] ) ) {
+ if ( isset( $submitted_data[ $key ] ) && $submitted_data[ $key ] > $array['max'] ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Maximum number limit is %s', 'ultimate-member' ), $array['max'] ) );
+ }
+ }
+
+ if ( empty( $array['validate'] ) ) {
+ continue;
+ }
+
+ switch ( $array['validate'] ) {
+
+ case 'custom':
+ $custom = $array['custom_validate'];
+ /**
+ * UM hook
+ *
+ * @type action
+ * @title um_custom_field_validation_{$custom}
+ * @description Submit form validation for custom field
+ * @input_vars
+ * [{"var":"$key","type":"string","desc":"Field Key"},
+ * {"var":"$field","type":"array","desc":"Field Data"},
+ * {"var":"$args","type":"array","desc":"Form Arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_action( 'um_custom_field_validation_{$custom}', 'function_name', 10, 3 );
+ * @example
+ *
+ */
+ do_action( "um_custom_field_validation_{$custom}", $key, $array, $submitted_data );
+ break;
+
+ case 'numeric':
+ if ( $submitted_data[ $key ] && ! is_numeric( $submitted_data[ $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( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'Please enter a valid phone number', 'ultimate-member' ) );
+ }
+ break;
+
+ case 'youtube_url':
+ if ( ! UM()->validation()->is_url( $submitted_data[ $key ], 'youtube.com' ) && ! UM()->validation()->is_url( $submitted_data[ $key ], 'youtu.be' ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
+ }
+ break;
+
+ case 'spotify_url':
+ if ( ! UM()->validation()->is_url( $submitted_data[ $key ], 'open.spotify.com' ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s URL', 'ultimate-member' ), $array['label'] ) );
+ }
+ break;
+
+ case 'telegram_url':
+ if ( ! UM()->validation()->is_url( $submitted_data[ $key ], 't.me' ) ) {
+ 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( $submitted_data[ $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( $submitted_data[ $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( $submitted_data[ $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( $submitted_data[ $key ], 'instagram.com' ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s profile URL', 'ultimate-member' ), $array['label'] ) );
+ }
+ break;
+
+ case 'linkedin_url':
+ if ( ! UM()->validation()->is_url( $submitted_data[ $key ], 'linkedin.com' ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
+ }
+ break;
+
+ case 'discord':
+ if ( ! UM()->validation()->is_discord_id( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'Please enter a valid Discord ID', 'ultimate-member' ) );
+ }
+ break;
+
+ case 'tiktok_url':
+
+ if ( ! UM()->validation()->is_url( $submitted_data[ $key ], 'tiktok.com' ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s profile URL', 'ultimate-member' ), $array['label'] ) );
+ }
+ break;
+
+ case 'twitch_url':
+
+ if ( ! UM()->validation()->is_url( $submitted_data[ $key ], 'twitch.tv' ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s profile URL', 'ultimate-member' ), $array['label'] ) );
+ }
+ break;
+
+ case 'reddit_url':
+
+ if ( ! UM()->validation()->is_url( $submitted_data[ $key ], 'reddit.com' ) ) {
+ UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s profile URL', 'ultimate-member' ), $array['label'] ) );
+ }
+ break;
+
+ case 'url':
+ if ( ! UM()->validation()->is_url( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'Please enter a valid URL', 'ultimate-member' ) );
+ }
+ break;
+
+ case 'unique_username':
+
+ if ( $submitted_data[ $key ] == '' ) {
+ UM()->form()->add_error( $key, __( 'You must provide a username', 'ultimate-member' ) );
+ } elseif ( $mode == 'register' && username_exists( sanitize_user( $submitted_data[ $key ] ) ) ) {
+ UM()->form()->add_error( $key, __( 'The username you entered is incorrect', 'ultimate-member' ) );
+ } elseif ( is_email( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'Username cannot be an email', 'ultimate-member' ) );
+ } elseif ( ! UM()->validation()->safe_username( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'Your username contains invalid characters', 'ultimate-member' ) );
}
- if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) {
- if ( $args[ $key ] && mb_strlen( $args[ $key ] ) < $array['min_chars'] ) {
- if ( empty( $array['label'] ) ) {
- UM()->form()->add_error( $key, sprintf( __( 'This field must contain at least %s characters', 'ultimate-member' ), $array['min_chars'] ) );
- } else {
- UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain at least %s characters', 'ultimate-member' ), $array['label'], $array['min_chars'] ) );
- }
- }
+ break;
+
+ case 'unique_username_or_email':
+
+ if ( $submitted_data[ $key ] == '' ) {
+ UM()->form()->add_error( $key, __( 'You must provide a username or email', 'ultimate-member' ) );
+ } elseif ( $mode == 'register' && username_exists( sanitize_user( $submitted_data[ $key ] ) ) ) {
+ UM()->form()->add_error( $key, __( 'The username you entered is incorrect', 'ultimate-member' ) );
+ } elseif ( $mode == 'register' && email_exists( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member' ) );
+ } elseif ( ! UM()->validation()->safe_username( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'Your username contains invalid characters', 'ultimate-member' ) );
}
- if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) {
- if ( $args[ $key ] && mb_strlen( $args[ $key ] ) > $array['max_chars'] ) {
- if ( empty( $array['label'] ) ) {
- UM()->form()->add_error( $key, sprintf( __( 'This field must contain less than %s characters', 'ultimate-member' ), $array['max_chars'] ) );
- } else {
- UM()->form()->add_error( $key, sprintf( __( 'Your %s must contain less than %s characters', 'ultimate-member' ), $array['label'], $array['max_chars'] ) );
- }
- }
- }
+ break;
- if ( isset( $array['type'] ) && $array['type'] == 'textarea' && UM()->profile()->get_show_bio_key( $args ) !== $key ) {
- if ( ! isset( $array['html'] ) || $array['html'] == 0 ) {
- if ( wp_strip_all_tags( $args[ $key ] ) != trim( $args[ $key ] ) ) {
- UM()->form()->add_error( $key, __( 'You can not use HTML tags here', 'ultimate-member' ) );
- }
- }
- }
+ case 'unique_email':
- if ( isset( $array['force_good_pass'] ) && $array['force_good_pass'] && ! empty( $args['user_password'] ) ) {
- if ( isset( $args['user_login'] ) && strpos( strtolower( $args['user_login'] ), strtolower( $args['user_password'] ) ) > -1 ) {
- UM()->form()->add_error( 'user_password', __( 'Your password cannot contain the part of your username', 'ultimate-member' ));
+ $submitted_data[ $key ] = trim( $submitted_data[ $key ] );
+
+ if ( in_array( $key, array( 'user_email' ) ) ) {
+
+ if ( ! isset( $submitted_data['user_id'] ) ){
+ $submitted_data['user_id'] = um_get_requested_user();
}
- if ( isset( $args['user_email'] ) && strpos( strtolower( $args['user_email'] ), strtolower( $args['user_password'] ) ) > -1 ) {
- UM()->form()->add_error( 'user_password', __( 'Your password cannot contain the part of your email address', 'ultimate-member' ));
+ $email_exists = email_exists( $submitted_data[ $key ] );
+
+ if ( $submitted_data[ $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, __( 'The email you entered is incorrect', 'ultimate-member' ) );
+ } elseif ( in_array( $mode, array( 'profile' ) ) && $email_exists && $email_exists != $submitted_data['user_id'] ) {
+ UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member' ) );
+ } elseif ( ! is_email( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member') );
+ } elseif ( ! UM()->validation()->safe_username( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'Your email contains invalid characters', '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' ) );
- }
- }
+ } else {
- if ( ! empty( $array['force_confirm_pass'] ) ) {
- if ( ! array_key_exists( 'confirm_' . $key, $args ) && ! UM()->form()->has_error( $key ) ) {
- UM()->form()->add_error( 'confirm_' . $key, __( 'Please confirm your password', 'ultimate-member' ) );
- } else {
- 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 ( $submitted_data[ $key ] != '' && ! is_email( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member' ) );
+ } elseif ( $submitted_data[ $key ] != '' && email_exists( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member' ) );
+ } elseif ( $submitted_data[ $key ] != '' ) {
- 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'] ) );
- }
- }
+ $users = get_users( 'meta_value=' . $submitted_data[ $key ] );
- 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( $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'] ) );
- }
- }
-
- 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'] ) );
- }
- }
-
- if ( ! empty( $array['validate'] ) ) {
-
- switch( $array['validate'] ) {
-
- case 'custom':
- $custom = $array['custom_validate'];
- /**
- * UM hook
- *
- * @type action
- * @title um_custom_field_validation_{$custom}
- * @description Submit form validation for custom field
- * @input_vars
- * [{"var":"$key","type":"string","desc":"Field Key"},
- * {"var":"$field","type":"array","desc":"Field Data"},
- * {"var":"$args","type":"array","desc":"Form Arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_custom_field_validation_{$custom}', 'function_name', 10, 3 );
- * @example
- *
- */
- do_action( "um_custom_field_validation_{$custom}", $key, $array, $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' ) );
- }
- 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' ) );
- }
- break;
-
- case 'youtube_url':
- if ( ! UM()->validation()->is_url( $args[ $key ], 'youtube.com' ) && ! UM()->validation()->is_url( $args[ $key ], 'youtu.be' ) ) {
- UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
- }
- break;
-
- case 'spotify_url':
- if ( ! UM()->validation()->is_url( $args[ $key ], 'open.spotify.com' ) ) {
- UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s URL', 'ultimate-member' ), $array['label'] ) );
- }
- break;
-
- case 'telegram_url':
- if ( ! UM()->validation()->is_url( $args[ $key ], 't.me' ) ) {
- 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'] ) );
- }
- 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'] ) );
- }
- 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'] ) );
- }
- break;
-
- case 'instagram_url':
-
- 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 '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'] ) );
- }
- break;
-
- case 'discord':
- if ( ! UM()->validation()->is_discord_id( $args[ $key ] ) ) {
- UM()->form()->add_error( $key, __( 'Please enter a valid Discord ID', 'ultimate-member' ) );
- }
- break;
-
- case 'tiktok_url':
-
- if ( ! UM()->validation()->is_url( $args[ $key ], 'tiktok.com' ) ) {
- UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s profile URL', 'ultimate-member' ), $array['label'] ) );
- }
- break;
-
- case 'twitch_url':
-
- if ( ! UM()->validation()->is_url( $args[ $key ], 'twitch.tv' ) ) {
- UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s profile URL', 'ultimate-member' ), $array['label'] ) );
- }
- break;
-
- case 'reddit_url':
-
- if ( ! UM()->validation()->is_url( $args[ $key ], 'reddit.com' ) ) {
- UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s 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' ) );
- }
- break;
-
- case 'unique_username':
-
- 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, __( 'The username you entered is incorrect', '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 ] ) ) {
- UM()->form()->add_error( $key, __( 'Your username contains invalid characters', 'ultimate-member' ) );
- }
-
- break;
-
- case 'unique_username_or_email':
-
- if ( $args[ $key ] == '' ) {
- UM()->form()->add_error( $key, __( 'You must provide a username or email', 'ultimate-member' ) );
- } elseif ( $mode == 'register' && username_exists( sanitize_user( $args[ $key ] ) ) ) {
- UM()->form()->add_error( $key, __( 'The username you entered is incorrect', 'ultimate-member' ) );
- } elseif ( $mode == 'register' && email_exists( $args[ $key ] ) ) {
+ foreach ( $users as $user ) {
+ if ( $user->ID != $submitted_data['user_id'] ) {
UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member' ) );
- } elseif ( ! UM()->validation()->safe_username( $args[ $key ] ) ) {
- UM()->form()->add_error( $key, __( 'Your username contains invalid characters', 'ultimate-member' ) );
}
-
- break;
-
- case 'unique_email':
-
- $args[ $key ] = trim( $args[ $key ] );
-
- if ( in_array( $key, array( 'user_email' ) ) ) {
-
- 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' ) );
- } elseif ( in_array( $mode, array( 'register' ) ) && $email_exists ) {
- UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member' ) );
- } elseif ( in_array( $mode, array( 'profile' ) ) && $email_exists && $email_exists != $args['user_id'] ) {
- UM()->form()->add_error( $key, __( 'The email you entered is incorrect', 'ultimate-member' ) );
- } elseif ( ! is_email( $args[ $key ] ) ) {
- UM()->form()->add_error( $key, __( 'The email you entered is incorrect', '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, __( 'The email you entered is incorrect', 'ultimate-member' ) );
- } elseif ( $args[ $key ] != '' && email_exists( $args[ $key ] ) ) {
- UM()->form()->add_error( $key, __( 'The email you entered is incorrect', '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, __( 'The email you entered is incorrect', 'ultimate-member' ) );
- }
- }
-
- }
-
- }
-
- break;
-
- case 'is_email':
-
- $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' ) );
- }
-
- 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 ) {
- UM()->form()->add_error( $key , __( 'You must provide a unique value', 'ultimate-member' ) );
- }
- }
- break;
-
- case 'alphabetic':
-
- if ( $args[ $key ] != '' ) {
-
- if ( ! preg_match( '/^\p{L}+$/u', str_replace( ' ', '', $args[ $key ] ) ) ) {
- UM()->form()->add_error( $key, __( 'You must provide alphabetic letters', 'ultimate-member' ) );
- }
-
- }
-
- break;
-
- case 'lowercase':
-
- if ( $args[ $key ] != '' ) {
-
- if ( ! ctype_lower( str_replace(' ', '', $args[ $key ] ) ) ) {
- UM()->form()->add_error( $key , __( 'You must provide lowercase letters.', 'ultimate-member' ) );
- }
- }
-
- break;
+ }
}
}
- }
+ break;
- if ( isset( $args['description'] ) ) {
- $max_chars = UM()->options()->get( 'profile_bio_maxchars' );
- $profile_show_bio = UM()->options()->get( 'profile_show_bio' );
+ case 'is_email':
- if ( $profile_show_bio ) {
- if ( mb_strlen( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $args['description'] ) ) > $max_chars && $max_chars ) {
- UM()->form()->add_error( 'description', sprintf( __( 'Your user description must contain less than %s characters', 'ultimate-member' ), $max_chars ) );
+ $submitted_data[ $key ] = trim( $submitted_data[ $key ] );
+
+ if ( $submitted_data[ $key ] != '' && ! is_email( $submitted_data[ $key ] ) ) {
+ UM()->form()->add_error( $key, __( 'This is not a valid email', 'ultimate-member' ) );
+ }
+
+ break;
+
+ case 'unique_value':
+
+ if ( $submitted_data[ $key ] != '' ) {
+
+ $args_unique_meta = array(
+ 'meta_key' => $key,
+ 'meta_value' => $submitted_data[ $key ],
+ 'compare' => '=',
+ 'exclude' => array( $submitted_data['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' ) );
+ }
+ }
+ break;
+
+ case 'alphabetic':
+
+ if ( $submitted_data[ $key ] != '' ) {
+
+ if ( ! preg_match( '/^\p{L}+$/u', str_replace( ' ', '', $submitted_data[ $key ] ) ) ) {
+ UM()->form()->add_error( $key, __( 'You must provide alphabetic letters', 'ultimate-member' ) );
+ }
+
+ }
+
+ break;
+
+ case 'lowercase':
+
+ if ( $submitted_data[ $key ] != '' ) {
+
+ if ( ! ctype_lower( str_replace(' ', '', $submitted_data[ $key ] ) ) ) {
+ UM()->form()->add_error( $key , __( 'You must provide lowercase letters.', 'ultimate-member' ) );
}
}
- }
+ break;
- } // end if ( isset in args array )
- }
+ }
+
+ if ( isset( $submitted_data['description'] ) ) {
+ $max_chars = UM()->options()->get( 'profile_bio_maxchars' );
+ $profile_show_bio = UM()->options()->get( 'profile_show_bio' );
+
+ if ( $profile_show_bio ) {
+ if ( mb_strlen( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $submitted_data['description'] ) ) > $max_chars && $max_chars ) {
+ UM()->form()->add_error( 'description', sprintf( __( 'Your user description must contain less than %s characters', 'ultimate-member' ), $max_chars ) );
+ }
+ }
+ }
+ } // end if ( isset in args array )
}
-add_action( 'um_submit_form_errors_hook_', 'um_submit_form_errors_hook_', 10 );
+add_action( 'um_submit_form_errors_hook_', 'um_submit_form_errors_hook_', 10, 2 );
/**
diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php
index 5d3328c5..f2512b0b 100644
--- a/includes/core/um-actions-profile.php
+++ b/includes/core/um-actions-profile.php
@@ -586,16 +586,18 @@ add_action( 'um_user_edit_profile', 'um_user_edit_profile', 10 );
/**
- * @param array $post_form
+ * Validate nonce when profile form submit.
+ *
+ * @param array $submitted_data
*/
-function um_profile_validate_nonce( $post_form ) {
- $user_id = isset( $post_form['user_id'] ) ? $post_form['user_id'] : '';
- $nonce = isset( $post_form['profile_nonce'] ) ? $post_form['profile_nonce'] : '';
+function um_profile_validate_nonce( $submitted_data ) {
+ $user_id = isset( $submitted_data['user_id'] ) ? $submitted_data['user_id'] : '';
+ $nonce = isset( $submitted_data['profile_nonce'] ) ? $submitted_data['profile_nonce'] : '';
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'um-profile-nonce' . $user_id ) ) {
- wp_die( __( 'This is not possible for security reasons.', 'ultimate-member' ) );
+ wp_die( esc_html__( 'This is not possible for security reasons.', 'ultimate-member' ) );
}
}
-add_action( 'um_submit_form_errors_hook__profile', 'um_profile_validate_nonce', 10, 1 );
+add_action( 'um_submit_form_errors_hook__profile', 'um_profile_validate_nonce', 1 );
add_filter( 'um_user_pre_updating_files_array', array( UM()->validation(), 'validate_files' ), 10, 1 );
diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php
index 3bf016ce..9d35811e 100644
--- a/includes/core/um-actions-register.php
+++ b/includes/core/um-actions-register.php
@@ -267,13 +267,18 @@ function um_check_user_status( $user_id, $args ) {
}
add_action( 'um_registration_complete', 'um_check_user_status', 100, 2 );
-function um_submit_form_errors_hook__registration( $args ) {
+/**
+ * Validate user password field on registration.
+ *
+ * @param array $submitted_data
+ */
+function um_submit_form_errors_hook__registration( $submitted_data ) {
// Check for "\" in password.
- if ( array_key_exists( 'user_password', $args ) && false !== strpos( wp_unslash( trim( $args['user_password'] ) ), '\\' ) ) {
+ if ( array_key_exists( 'user_password', $submitted_data ) && false !== strpos( wp_unslash( trim( $submitted_data['user_password'] ) ), '\\' ) ) {
UM()->form()->add_error( 'user_password', __( 'Passwords may not contain the character "\\".', 'ultimate-member' ) );
}
}
-add_action( 'um_submit_form_errors_hook__registration', 'um_submit_form_errors_hook__registration', 10, 1 );
+add_action( 'um_submit_form_errors_hook__registration', 'um_submit_form_errors_hook__registration' );
/**
* Registration form submit handler.