Support

Account

Home Forums Front-end Issues Don't update email if it exists. Show error on same page in Reply To: Don't update email if it exists. Show error on same page in

  • Here is what I came up with:

    add_filter('acf/validate_value/name=my_user_email', 'my_acf_validate_value', 10, 4);
    
    function my_acf_validate_value( $valid, $value, $field, $input ){
    	
    	if($value == "" || $value == " ") {
    		$valid = "Email field cannot be empty";
    	} elseif( email_exists($value) ) {
    		$valid = "This email already exists. Use a unique email";
    	}
    	return $valid;
    	
    }

    If a users email is info@website.com and they try another email that already exists or nothing then they get the respective errors. So far so good. If they try to change their email back to info@website.com they can’t because of the email_exists($value). Even though that is the what we want because they’re actual email is info@website.com. That was never changed. Can we do a check as follows

    If email exists then show error “This email exists already” unless the user’s actual email (wordpress user email) is the ACF field value being entered. Then that is OK and that is the exception.

    I can see users trying to change their email to something else. seeing the error. then saying “I’m going to change it back to my old email”. and if they do it exists because the WordPress email was never changed.

    So close

    If user