The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Check if user is admin - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: Check if user is admin (/showthread.php?tid=736)



Check if user is admin - c.l.f.wittmann@gmail.com - 09-11-2017

Is there a way to check whether the logged in user is a admin?


Check if user is admin - Brandin - 09-11-2017

You can use checkMenu or hasPerm.

if(checkMenu(2,$user->data()->id))

OR

hasPerm($permissions, $id)


Check if user is admin - mudmin - 09-11-2017

Note that hasPerm is made to be an array so it can do multiple levels at once, so it's expecting an array.

When you go into the admin panel and click admin permissions and then click a permission, if you look at this screenshot
http://puu.sh/xx701/7a52b51a58.png

You'll see that each permission has an id on it. By default, Admin is 2. If you add others like staff and manager, they'll come in at 3 & 4. Then you have to pass the user id into either checkMenu or hasPerm.

With that array, let's say you want permission levels 2 and 4 to be able to do something, that would be

Code:
if(hasPerm([2,4],$user->data()->id)){
Code:
//do something
Code:
}



Check if user is admin - c.l.f.wittmann@gmail.com - 09-11-2017

Thanks a lot. I solved it with the checkMenu(a,b) methode.