From d0c405b87ab534b7dd4e142360e6432f4048217d Mon Sep 17 00:00:00 2001 From: denisbaranov Date: Fri, 24 Apr 2020 18:23:47 +0300 Subject: [PATCH] Fixed: Role validation on registration. 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). --- includes/core/um-actions-form.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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] = ''; } /**