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).
This commit is contained in:
denisbaranov
2020-04-24 18:23:47 +03:00
parent 0acc9ad280
commit d0c405b87a
+4 -4
View File
@@ -457,10 +457,10 @@ function um_submit_form_errors_hook_( $args ) {
UM()->form()->add_error( $key, sprintf( __( '%s is required.', 'ultimate-member' ), $array['title'] ) ); UM()->form()->add_error( $key, sprintf( __( '%s is required.', 'ultimate-member' ), $array['title'] ) );
} }
if ( $key == 'role_select' || $key == 'role_radio' ) { /* 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 ( isset( $array['required'] ) && $array['required'] == 1 && ( ! isset( $args['role'] ) || empty( $args['role'] ) ) ) { 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()->add_error( 'role', __( 'Please specify account type.', 'ultimate-member' ) );
} UM()->form()->post_form[$key] = '';
} }
/** /**