• Resolved mickthemaker

    (@mickthemaker)


    Hello,

    I’m currently trying to set a custom user role before the user redirects. I’m using the hook um_registration_complete for this.

    My form has a field called bar_number (example) and I want to retrieve this field in the custom function for the hook, but unfortunately I do not know how.

    Code should look something like that
    add_action( ‘um_registration_complete’, ‘company_registration_complete’, 10, 2 );
    function company_registration_complete( $user_id, $args ) {
    // 1. retrieve field (how)
    $bar_number = ……?;

    // 2. unset standard role
    $user_id->remove_role(‘um_standard’);

    if (something == 111) {
    // 3. set new role
    $user_id->set_role(‘admin’);
    }
    }`

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • @mickthemaker

    You can try this code snippet.

    add_action( 'um_registration_complete', 'company_registration_complete', 10, 2 );
    
    function company_registration_complete( $user_id, $args ) {
    
        // 1. retrieve field (how)
        $bar_number = $args['submitted']['bar_number'];
    
        // 2. unset standard role
        $user = new WP_User( $user_id );
        $user->remove_role( 'um_standard' );
    
        if ( $something == 111 ) {
            // 3. set new role
            $user->set_role( 'admin' );
        }
    }

    Question: If $something != 111 the user will be without a role?

    Thread Starter mickthemaker

    (@mickthemaker)

    Thanks heaps, this worked just fine.

    The validation was a bit longer than that, so if something != 111 then another case would step in.

    • This reply was modified 3 years, 2 months ago by mickthemaker.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @mickthemaker

    What’s exact validation do you use? Could you please share them?

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    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)
  • The topic ‘Get registration field names for hook um_registration_complete’ is closed to new replies.