Replacing isguest() with 1.7 roles

Replacing isguest() with 1.7 roles

על ידי Alex Little בתאריך
מספר תגובות: 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

ממוצע דרוגים: -
בתגובה ל: Alex Little

Re: Replacing isguest() with 1.7 roles

על ידי Howard Miller בתאריך
תמונה של Core developers תמונה של Documentation writers תמונה של Particularly helpful Moodlers תמונה של Peer reviewers תמונה של 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.
בתגובה ל: Alex Little

Re: Replacing isguest() with 1.7 roles

על ידי Martin Dougiamas בתאריך
תמונה של Core developers תמונה של Documentation writers תמונה של Moodle HQ תמונה של Particularly helpful Moodlers תמונה של Plugin developers תמונה של 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.