• Resolved wilterson

    (@wilterson)


    Hi.

    How can i add multiple roles to a user via code.?
    In user’s login hook, I add the code below.

    $roles = array( 'role1', 'role2', 'role3', 'role4' );
    foreach ($roles as $key => $role) {
          wp_update_user( array(
    	                  'ID' => $user_id,  //User logged
    			  'role' => $role    //From array $roles
    		));
    }

    But the user only remains with the last role in the iteration.

    Any sugestion?

    Thanks.

    https://wordpress.org/plugins/members/

Viewing 2 replies - 1 through 2 (of 2 total)
  • You don’t need to use code. When on the edit user screen, you can check multiple roles at once.

    Justin, is there a way to set multiple roles on user registration (not on User Edit), as with the “User Role Editor” plugin?

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple roles to a user’ is closed to new replies.