Search code examples
phpcodeigniterexpressionengine

Expression Engine: Matching Users to Member Groups


Hi I am currently writing a few functions for various hooks such as

and I need to work out what member group the current user belongs to. So far to get the extension up and running I have been writing IF statements with hard coded ids like so

CODE EXAMPLE:

if($this->EE->session->userdata('group_id') == 5){ //do something } 

Is there a standard way to match users to member groups?


Solution

  • If you are making an extension or module, and need a list of available groups to choose from on the settings page, then you can load the member model and use get_member_groups() to get a list.

    EE setup installs the default groups as

    (1) Super Admins
    (2) Banned
    (3) Guests (visitors)
    (4) Pending (registered, but not yet validated)
    (5) Members
    

    Any other groups you come up with will have a higher ID than 5. Picking the hard-coded value for 'members', is probably safe.