Jump to content

Adding role to many users


Manaus
 Share

Recommended Posts

Hello,

I need to add the guest role to so many users I just added [using a csv] to $users pool, is there any way to make it from the backend?

I'm also trying to code it, but I don't know how to make up the selector

$usersWithoutRole = $users->find("roles*=gooduser,roles!*=guest, roles!=superuser")

Thanks

Link to comment
Share on other sites

You can write that as something like this (pipe symbol | means OR):

$usersWithoutRole = $users->find("roles!=gooduser|guest|superuser");

You don't need to try and partial match if you know the exact names of the roles.

If you just want to make sure every user has the guest role though, just re-add it regardless of whether they have it or not like this:

foreach ($users as $u) {
    $u->addRole('guest');
    $u->save();
}
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...