• Resolved emmamiumiu

    (@emmamiumiu)


    Hi !

    I have this code to be able to change my email from the profile form

    add_action("um_submit_form_profile","add_field", 1 );
    function add_field( $post_form ){
       
        //user mail
        if( isset( $post_form['user_email'] ) && ! empty( $post_form['user_email'] ) ){
            $user = wp_get_current_user();
    
            if( email_exists( $post_form['user_email'] ) && $post_form['user_email'] !== $user->user_email ){
                UM()->form()->add_error( 'user_email', __( 'Your email address is already taken', 'ultimate-member' ) );
            }
        }
    }

    And i also have added user_email error via this one (In the profile form ive set up the validate as custom)

    add_action( 'um_custom_field_validation_user_email_details', 'um_custom_validate_user_email_details', 999, 3 );
    function um_custom_validate_user_email_details( $key, $array, $args ) {
    	if ( $key == 'user_email' && isset( $args['user_email'] ) ) {
    		if ( isset( UM()->form()->errors['user_email'] ) ) {
    			unset( UM()->form()->errors['user_email'] );
    		}
    		if ( empty( $args['user_email'] ) ) {
    			UM()->form()->add_error( 'user_email', __( 'E-mail Address is required', 'ultimate-member' ) );
    		} elseif ( ! is_email( $args['user_email'] ) ) {
    			UM()->form()->add_error( 'user_email', __( 'The email you entered is invalid', 'ultimate-member' ) );
    		} elseif ( email_exists( $args['user_email'] ) ) {
    			UM()->form()->add_error( 'user_email', __( 'The email you entered is already registered', 'ultimate-member' ) );
    		}
    	}
    
    }

    So, even if i dont change my email, i have “The email you entered is already registered”.

    For my profile form i want email to be if empty, if it’s an invalid email, if the email is already taken by someone else.

    I’ve tried to remove the valide custom check but then the only error i get is “The email you entered is incorrect”

    Any way to custom the code in the profile form too ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hello @emmamiumiu,

    The “E-mail Address” field is not editable in profile. We locked this field because of security reasons. Members can change their E-mail Address in their account.

    You can use the um_user_profile_restricted_edit_fields hook to exclude this field from disabled in edit mode, but this is not recommended. You can get a code from example in the hook documentation: https://ultimatemember.github.io/ultimatemember/hooks/um_user_profile_restricted_edit_fields.html

    The code snippet you use validates E-mail Address for new users on registration. You need to set another rule to validate E-mail Address for existing users. I recommend using the default “Unique E-mail” rule to validate the “E-mail Address” field in the profile form.

    Regards

    Plugin Support andrewshu

    (@andrewshu)

    Hi @emmamiumiu

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Profile form is not updated if email is not changed’ is closed to new replies.