Jump to content

Show all roles a user has via API


renobird
 Share

Recommended Posts

Hello all,

A bit dense today, so hopefully someone can help me.

I'm trying to show a list of all the roles a user has using the API.

$users = $pages->find("parent=/processwire/access/users/");
foreach ($users as $user) {
echo $user->name . " - " . $user->roles . "<br />";
}

$user->roles returns a page array, so I get something like 1015|2263|2273

What I need is the name of the role instead of the page ID.

Duh! $user-roles is an array, need to use foreach to return the name.

Sorry, told you I was being dense today.

As you were.

:)

  • Like 1
Link to comment
Share on other sites

Also want to mention that you don't need to do the $pages->find(); because ProcessWire already provides you with a $users API variable. The $users API variable is like a special $pages API variable that only acts on users. Though unlike the $pages API variable, you can foreach($users).

  • Like 1
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...