Title: Registration code
Last modified: October 27, 2021

---

# Registration code

 *  [israfel78](https://wordpress.org/support/users/israfel78/)
 * (@israfel78)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/registration-code-2/)
 * 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](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/registration-code-2/#post-15014073)
 * Hi [@israfel78](https://wordpress.org/support/users/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](https://wordpress.org/support/users/israfel78/)
 * (@israfel78)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/registration-code-2/#post-15035375)
 * 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](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/registration-code-2/#post-15272269)
 * Hi [@israfel78](https://wordpress.org/support/users/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/](https://wordpress.org/support/plugin/ultimate-member/)
 * Regards,

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Registration code’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * Last activity: [4 years, 4 months ago](https://wordpress.org/support/topic/registration-code-2/#post-15272269)