Support » Plugin: Ultimate Member – User Profile, User Registration, Login & Membership Plugin » Create custom validation that checks against all other users

  • Resolved chronosphere

    (@chronosphere)


    I have already coded a custom validation that checks an ID against a custom regular expression, but I would like to further enhance the validation by making sure no other users have that particular ID. Any advice on how to accomplish this? It seems that the built-in email validation has this feature, so I believe this request should be possible.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Aswin Giri

    (@aswingiri)

    Hello @chronosphere

    Are you trying to validate a custom field or built in username?

    Thread Starter chronosphere

    (@chronosphere)

    I am trying to validate a custom field, yes.

    Plugin Support Aswin Giri

    (@aswingiri)

    Hello @chronosphere

    Please try following code snippets:

    function um_custom_validate_userid( $key, $array, $args ) {
    
    	 
    	if ( isset( $args[$key] ) ) {
    
    		$users = get_users( array(
        		'meta_key' => 'userid_meta_key',
        		'meta_value' => $args[$key]
    		));
    
    		if( ! empty($users )){
    			UM()->form()->add_error( $key, __( 'userid is not unique.', 'ultimate-member' ) );
    		}
    		
    	}
    }
    add_action( 'um_custom_field_validation_userid', 'um_custom_validate_userid', 30, 3 );

    Please remember to replace ‘userid‘ and userid_meta_key. You can also follow this documentation regarding custom validation.

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hey there!

    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 by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. 🙂

    Regards,

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.