1
natxocc
How to check if user is admin
  • 2005/2/1 21:44

  • natxocc

  • Just popping in

  • Posts: 19

  • Since: 2005/1/23


I think the the correct code is:

if ($xoopsUserIsAdmin)
{
...



but it doesn't work

I wanted to use it in php file not in template.

Is there other option to do this?

2
natxocc
Re: How to check if user is admin
  • 2005/2/1 22:17

  • natxocc

  • Just popping in

  • Posts: 19

  • Since: 2005/1/23


I found it!


if ($xoopsUser)
{
if ($xoopsUser->isAdmin(-1))
{
...

3
jdseymour
Re: How to check if user is admin

Here is a snippet out of kernel/user.php Maybe it will help:

/**
     * Is the user admin ?
     *
     * This method will return true if this user has admin rights for the specified module.<br />
     * - If you don't specify any module ID, the current module will be checked.<br />
     * - If you set the module_id to -1, it will return true if the user has admin rights for at least one module
     *
     * @param int $module_id check if user is admin of this module
     * @return bool is the user admin of that module?
     */
    
function isAdmin( $module_id = null ) {
        if ( 
is_null( $module_id ) ) {
            
$module_id = isset($GLOBALS['xoopsModule']) ? $GLOBALS['xoopsModule']->getVar( 'mid', 'n' ) : 1;
        } elseif ( 
intval($module_id) < 1 ) {
            
$module_id = 0;
        }
        
$moduleperm_handler =& xoops_gethandler('groupperm');
        return 
$moduleperm_handler->checkRight('module_admin', $module_id, $this->getGroups());
    }


4
natxocc
Re: How to check if user is admin
  • 2005/2/2 19:21

  • natxocc

  • Just popping in

  • Posts: 19

  • Since: 2005/1/23


thanks!

it was useful!!