1

I have the following code:

<?php if ($user->id >= 1): // logged in ?>

This checks to see if the user is logged in, but not which group the user belongs to. I'm trying to show content only for registered users.

1
  • Welcome to JSE. Please take our tour.
    – mickmackusa
    Feb 9 at 23:50

2 Answers 2

2

Resolved with the following code:

I just needed to discover a way of grabbing either the group name or user group id.

We do the latter and grab the id of the group we wish to manipulate. All user group ids of the current user are added to an array ($groups). Then we search that array for the group id we need.

$user   = JFactory::getUser();
$groups = $user->get('groups');

if (in_array(2, $groups))
1

A quick search turns up a couple of answers that give you a list of groups the user belongs to that you can then process to determine if the group is the Registered group.

This answer is for J2.5 but still looks like it will work. https://stackoverflow.com/questions/18407595/get-user-group-id-in-joomla-with-php/18407692

This answer is more comprehensive and should be enough for you to progress. How to know which usergroup/specific access level user belongs to

1
  • Ah brilliant, thanks for that. Resolved it.
    – suge1w
    Feb 10 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.