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

Joomla 3 - Add language file support for plugins

Do this...

/**
* Load the language file on instantiation.
*
* @var    boolean
* @since  3.1
*/
protected $autoloadLanguage = true;

Generic domains names now available

Here's a full list of "Generic" domain names you probably never thought were available (register at http://hosting.noxidsoft.com):
.technology
.international
.wiki
.tattoo
.university

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.

Login Form