• Hi,
    is there a way to get a user to register only if they enter a code that is given to them first?

    I would like to register only users who have the code that I provide separately.

    Best Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @israfel78

    You can try adding a text field with a meta key ‘pass_code’ to your register form for users to enter the code and then add the following code snippet to your site:

    add_action("um_submit_form_register","um_102821_passcode");
    function um_102821_passcode( $post_form ){
      
        if(  isset( $post_form['pass_code'] ) && ! empty( $post_form['pass_code'] ) ){ 
                if( $post_form['pass_code'] !== "mypasscode" ){ 
                  UM()->form()->add_error('pass_code', __( 'Invalid pass code', 'ultimate-member' ) );
                }
    	
        }  
    
        if(  empty( $post_form['pass_code'] ) ){ 
             UM()->form()->add_error('pass_code', __( 'Enter a pass code', 'ultimate-member' ) );
        }
    
    }

    The above code will validate the pass_code field. If they enter the pass code mypasscode incorrectly the error will show Invalid pass code in the form.

    Regards,

    Thread Starter israfel78

    (@israfel78)

    Hi Camp Camba,

    thank you so much for your answer.
    The only thing that is not clear to me is where to put the code.
    Do I have to insert it in a UM parcular file?
    in case you could tell me which one?

    Beste regards
    Enrico

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @israfel78

    Sorry for the late response.

    You can add the code to your theme/child-theme’s functions.php file or use the Code Snippet plugin to run the code.

    If you have issues, please create a topic on the forum instead:
    https://wordpress.org/support/plugin/ultimate-member/

    Regards,

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