Reputation: 3523
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?
Upvotes: 1
Views: 458
Reputation: 880
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.
Upvotes: 4
Reputation: 680
If you are using PHP that is indeed the only way.
You can also access it via an array like this:
$this->EE->session->userdata['group_id']
Upvotes: 4