diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 6e17a832..9989362b 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -457,10 +457,10 @@ function um_submit_form_errors_hook_( $args ) { 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' ) ); - } + /* 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] = ''; } /**