Add Wordpress user in more than one function

Asked

Viewed 55 times

3

I am developing a plugin for member area in Wordpress and I will control this access through the functions (roles).

Suppose I create the functions: content1, content2 and content3. How I could assign more than one function 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 ) ;

1 answer

3


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

A string used to set the user’s role.

In free translation

String used for "set" to "role" user’s

At least for me, it seems that it is only possible to pass one role and ready. I would try pass two values separated by comma, I don’t know if it works, it’s just a hint.

Anyway it is possible to add the roles after creating the user

$userid = wp_insert_user($userdata);
$user = new WP_User($userid);
$user->add_role('conteudo1');
$user->add_role('conteudo2');
  • 1

    passing comma separated values will not work. add_role() yes.

  • It worked that way, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.