Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Multiple roles help #4780
    siadicicco
    Spectator

    I am trying to remove and add a (or many) role on a form update and I am at a road block:
    Do you have any insight?

    add_action(‘frm_after_create_entry’, ‘newweb_to_website’, 20, 2);
    function newweb_to_website($entry_id, $form_id){
    if($form_id == 41){
    if ( $user_role == ‘customer’ ) {
    $user->remove_role( ‘new-web’ );
    $user->add_role(‘website’);
    }

    $user = wp_get_current_user();
    if(!$user) {
    return;
    }

    $updated_user = (array)$user;

    // Get the highest/primary role for this user
    $user_roles = $user->roles;
    $user_role = array_shift($user_roles);
    if ( $user_role == ‘administrator’ )
    return; //make sure we don’t downgrade any admins

    $updated_user[‘role’] = $new_role;

    wp_update_user($updated_user);
    }
    }

Viewing 1 post (of 1 total)