Replacing isguest() with 1.7 roles

Replacing isguest() with 1.7 roles

by Alex Little -
Number of replies: 2
Hi,

I've been reading about the new roles & permissions stuff in 1.7, but I just don't quite 'get' what I'm actually meant to replace an isguest() function call with. The roles page (http://docs.moodle.org/en/Roles#Guests) says there will be still be a guest account, but with "no default role at site level" - but with the new functions (has_capability etc) what do I use to test if they have no role?

I know that just leaving isguest() will work for now - but I'd like to try and avoid using deprecated functions!
TIA,
Alex

Average of ratings: -
In reply to Alex Little

Re: Replacing isguest() with 1.7 roles

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Interestingly in the current code, the roles stuff is commented out in the isguest() function and it simply checks if the username (of the current user) is 'guest'. So, it seems the function won't work if you assign anybody other than 'guest' with guest rights.
In reply to Alex Little

Re: Replacing isguest() with 1.7 roles

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
isguest() is indeed deprecated and there for backward compatibility only.

A lot of new changes regarding all this will hit CVS soon, but basically even people who are not logged in will have a 'role' that has_capability can test against.  By default it's the guest role, but through $CFG->notloggedinrole you can change it to something else if you choose.

The short answer is: use has_capability() all the time.