• mhoc2022

    (@mhoc2022)


    Hi,

    I have a registration page setup for my website and I want the ability to have a form field where visitors wanting to create an account can input a specific code in order to get a higher user role than a regular member. This will allow users with the code to get access to special pages on my website that regular members dont.

    I have gotten as far as the custom validation option in the form fields editor but I am stuck on how to continue or unsure if this is even the best way to complete this task.

    Regular members will not be required to enter into the special “Partner Access Code” field I am talking about. If it has to be a completely separate form that is ok also because I can redirect with a button from the regular register page to the “Partner Registration” page. But I still dont know how to require a special code in order to get the special partner user account.

    Any help is greatly appreciated. Thanks.

    The page I need help with: [log in to see the link]

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

    (@aswingiri)

    Hello @mhoc2022

    If you have added custom validation to ‘partner access code’, you can just assign the user a new role after registration. Please check this code snippet for help.

    Thread Starter mhoc2022

    (@mhoc2022)

    @aswingiri

    Thanks for your reply,

    So there is no way to automate the process with your plugin? It has to be done manually to upgrade a user role?

    Thread Starter mhoc2022

    (@mhoc2022)

    Or sorry. I am looking at the code now.

    So if I make the partner access code “chocolate” and the user role “partner” for example:

    add_action( 'um_registration_complete', function( $user_id, $args ){
    		$partner_code = get_user_meta( $user_id ,'chocolate',true );
        if( $partner_code ){
        	/*
          	revalidate partner code
          */
          
          /* assign new role if partner code is valid */
          UM()->roles()->set_role( $user_id, 'partner');
        }
        
    },30, 2 );

    Is this correct? And the custom action in the form field would be “partner_code” ?

    • This reply was modified 2 years ago by mhoc2022.
    • This reply was modified 2 years ago by mhoc2022.
    Plugin Support Aswin Giri

    (@aswingiri)

    @mhoc2022 Yes, you can try the code snippet and see if that meets your requirement.

    Thread Starter mhoc2022

    (@mhoc2022)

    @aswingiri

    Does not seem to work. New user is still just a standard subscriber and not a partner. I think maybe I’m misunderstanding.

    This is a separate code from the custom validation code? So I still need a custom validation code with um_custom_field_validation_partner_code in my functions.php for the custom validation? What would the code for this look like?

    Plugin Support Aswin Giri

    (@aswingiri)

    Hello @mhoc2022

    Yes, it is separate from the custom validation code. The code snippet I provided will check for meta_value for the user once the registration process is complete and assigns the new role if the user has the metadata.

    You can also try changing action priority to something like the below:

    add_action( 'um_registration_complete', function( $user_id, $args ){
    		$partner_code = get_user_meta( $user_id ,'chocolate',true );
        if( $partner_code ){
        	/*
          	revalidate partner code
            please add your codes to validate the partner code here.
          */
          
          /* assign new role if partner code is valid */
          UM()->roles()->set_role( $user_id, 'partner');
        }
        
    },2, 2 );
    Thread Starter mhoc2022

    (@mhoc2022)

    @aswingiri Thank you for your help. I still am not getting the result.

    I am putting this code into code snippets plugin in functions.php and it still is not working. Is this the correct location?

    I do not have a custom validation code in my functions.php can you help with this? Or are you saying that it is not needed with the other code you provided?

    Right now in UM I edit the registration form and in my custom form field “Partner Code” I set Validate as Custom Validation and Custom Activation as partner_code

    In my user roles section of UM I made the new user role Partner but the user ID is um_partner

    I want the code that new user to put into the Parter Code field to be “chocolate” so that they will become a Partner instead of a Subscriber account when entered.

    Thank you for your time

    Thread Starter mhoc2022

    (@mhoc2022)

    Replying to see if there is any other help I can get on this topic. Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom Validation to Elevate Account Permission’ is closed to new replies.