alejandro Posted August 9, 2014 Share Posted August 9, 2014 Hello, when creating a new user via API without assining the role 'guest' it seems PW assigns it by default. But it doesn´t appear in the user list roles column. Although is seems to be assigned anyway when displaying the user page. Update: the guest role appears when the user is assigned another role in de admin. 1) Should I assign the guest role when creating the user with the API? (I guess it´s not necessary) 2) Is there, anyway, an API syntax to assign 2 roles at a time?: $u->addRole("guest, customer") (doesn´twork) -------------------------------------- $u->addRole("guest"); $u->addRole("customer";) it works but a bit repetitive Thanks. Link to comment Share on other sites More sharing options...
Nico Knoll Posted August 9, 2014 Share Posted August 9, 2014 No it's not possible in your syntax: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/User.php#L62 But you could do it like this (I think): $u->addRole("guest")->addRole("customer"); 1 Link to comment Share on other sites More sharing options...
alejandro Posted August 9, 2014 Author Share Posted August 9, 2014 Well, a bit cleaner Thank you. Link to comment Share on other sites More sharing options...
Nico Knoll Posted August 9, 2014 Share Posted August 9, 2014 But please try first. I'm not sure if this really works because "addRole" returns a boolean and not $page. Link to comment Share on other sites More sharing options...
alejandro Posted August 9, 2014 Author Share Posted August 9, 2014 It doesn´t work: Fatal error: Call to a member function addRole() on a non-object in /................ on line 150 So, back to the 2 lines method. Link to comment Share on other sites More sharing options...
adrian Posted August 9, 2014 Share Posted August 9, 2014 (edited) What about: foreach(array('guest', 'customer') as $r) $u->addRole($r); Still, I don't see any reason to add the guest role manually, so if you are only adding one other additional role, then you probably don't need anything to reduce multiple lines. It seems like maybe something changed recently. What version of PW are you running? If I test on 2.4.5 the guest role is automatically added, but not in 2.4.11 - https://github.com/ryancramerdesign/ProcessWire/issues/588 Wow - I am having a rough morning - nothing has changed - behavior seems to be consistent through versions. Edited August 9, 2014 by adrian 1 Link to comment Share on other sites More sharing options...
alejandro Posted August 9, 2014 Author Share Posted August 9, 2014 2.4.10 But the guest role is indeed added, just it doesn´t appear under the column roles in the user list. So, at first I had the doubt if it was necessary to add it via API. Link to comment Share on other sites More sharing options...
adrian Posted August 9, 2014 Share Posted August 9, 2014 2.4.10 But the guest role is indeed added, just it doesn´t appear under the column roles in the user list. So, at first I had the doubt if it was necessary to add it via API. I don't think it is actually added though - if you look at the field_roles database table and look for entry with a pages_id that matches the user, there won't be one. There should be one with a data: 37 (page id of the guest role). When you view the user page, there is some logic that ensures the guest role checkbox is checked, but it's not being stored in the database. Link to comment Share on other sites More sharing options...
alejandro Posted August 9, 2014 Author Share Posted August 9, 2014 You're right Adrian, no guest role is added. So I understand that upon user creation the "guest" role must be added. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now