Check a user is admin in Joomla 2.5.x

If you are modifying the edit form for Joomla 2.5.x or other form that requires a need to test if this is a Super Administrator just use the following. Handy if you need to block out certain functionality for different user groups but you still need full access to those options as an administrator.

Joomla 1.5.x world:

$user =& JFactory::getUser();
if($user->usertype == "Super Administrator" || $user->usertype == "Administrator") {
  echo 'You are an Administrator'; 
} else {
  echo 'You are just an ordinary user';
}

Joomla 2.5.x world (this will only check for Super Admins):

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

if ($isAdmin) {
  // code here
}

We really shouldn't do it that way though, a check for authorization is better because we can't really determine if a user has that access anyway, so do this:

$user = JFactory::getUser();
if($user->authorise('core.edit', 'com_contact')) {
  echo "Yes, I can edit contacts!";
} else {
  echo "No, I can't edit contacts";<
}
Share on Myspace

Latest News

Heartbleed security issue - OpenSSL

Do not rush to change all your passwords!

Let me qualify that statement. I have heard and seen many knee jerk reactions from "professionals" that state we should all rush out to change our banking and social media passwords. The first question we should be asking is, what, who, why. The second, do I need to make a change right away, if at all.

What systems are affected?

Simple. All systems that use the OpenSSL security certificate service.

Looking at Joomla 3.3

Create a HTML signature for Mac OS X Mavericks

This article describes the method for adding an email signature to your mail client under Mac OS X Mavericks (may be backward compatible with Lion too, untested).

Login Form