Add Wordpress user in more than one role

3

I'm developing a plugin for members area in WordPress and I'm going to control this access through the roles functions.

Assuming I create the functions: content1, content2, and content3. How would I be able to assign more than one role to a created user?

$website = site_url();

$cliente_userdata = array(
    'first_name' => 'Primeiro Nome',
    'user_login'  =>  'E-mail',
    'user_email' => 'E-mail',
    'user_url'    =>  $website,
    'role' => 'conteudo1',
    'user_pass'   =>  NULL // Cria Sózinho
);

wp_insert_user( $cliente_userdata ) ;
    
asked by anonymous 23.11.2016 / 19:12

1 answer

3

Directly I think it's impossible. The documentation is extremely shallow , it says the following

  

The string used to set the user's role.

Free Translation

  

String used to " set " to ""

At least for me, this implies that it is only possible to pass a role and that's it. I try to pass two values separated by a comma, I do not know if it works, it's just a tip.

In any case, you can add roles after creating the user

$userid = wp_insert_user($userdata);
$user = new WP_User($userid);
$user->add_role('conteudo1');
$user->add_role('conteudo2');
    
23.11.2016 / 19:33