HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Working out if a User is in a secondary group

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#103276 (In Topic #20224)
Avatar

Community saint

Hi,

I tweaked the side stats.php code a while ago to display the number of members in a particular group, in our case the paid members group.

I would like to only show the actual number now if the logged on user is a member of an admin group - the reason being is that we are going to run a competition as we get close to a 1000 user milestone and do not want users to see the total.

So I know what the group ID is of the group that I want the number to display for is.
What I really need is a function that checks to see if the currently logged on member is a member of that group (in our case it will always be a secondary group.)

I have searched OCP code for such a function but cannot locate one.
Cannot I just not see it or has someone written such a function that I can use ?

Cheers
Ade

Back to the top
 
Posted
Rating:
#103277
Avatar

Check if a member is in a group:

Code

in_array($group_id,$GLOBALS['FORUM_DRIVER']->get_members_groups($member_id))

Check if a member is specifically in an admin group:

Code

$GLOBALS['FORUM_DRIVER']->is_super_admin($member_id)


So we don't have a function to specifically check a specific group, but reading a list of groups lets you do that. But we do have a function for admins specifically already, as that is something we use in our code as it has an implicit meaning to ocPortal.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: