Page 1 of 1

Hiding menu items from userlevels

Posted: Thu Jan 11, 2018 7:12 pm
by cdmak

Hello,

I'm trying to hide a 3 menu items from the Administrator group level "-1" I looked at "MenuItem_Adding" in the help but it seems pretty vague, I don't want to clear the entire menu and then add back the menu items for admin, just want to hide a few.

Is there a way to do this simply?
Thank You


Re: Hiding menu items from userlevels

Posted: Thu Jan 11, 2018 7:30 pm
by kirondedshem

Read the help menu about the server events of the menu, coz MenuItem_Adding is called before rendering any menus item on themenu, And a menu item wont be drawn if you return false from this event even if it was supposed to be drawn. For example am hiding the home, news and cars menu items from the admin user in demo project.

// MenuItem Adding event
function MenuItem_Adding(&$Item) {

//var_dump($Item);
// Return FALSE if menu item not allowed

//the menu item is one of the following
if ($Item->url == "home.php" || $Item->url == "news.php" || $Item->url == "carslist.php")
{
            //get the user level of logged in user
	if(CurrentUserLevel() == -1)
	{
		return FALSE;//dont draw it
    }
	else
	{
		return TRUE;//draw it
	}
}
	
 
return TRUE;

}


Re: Hiding menu items from userlevels

Posted: Fri Jan 12, 2018 3:24 pm
by cdmak

Thank you again for your kind help, I understand this now, makes sense.


Re: Hiding menu items from userlevels Special Note

Posted: Mon Jan 15, 2018 4:49 pm
by cdmak

Special Note:

If the menu is not hidden click on the link and see what is displayed in the browser and copy and paste into the string, take a look at the carslist.php example below. Now the cars list will be hidden.

if ($Item->url == "home.php" $Item->url == "news.php" $Item->url == "carslist.php?cmd=resetall")

Thank You


Re: Hiding menu items from userlevels

Posted: Thu Jan 25, 2018 5:01 pm
by cdmak

Is it possible to put more users in this? I tried and it does not work. Thank You

// MenuItem Adding event
function MenuItem_Adding(&$Item) {

//var_dump($Item);
// Return FALSE if menu item not allowed

//the menu item is one of the following
if ($Item->url == "home.php" $Item->url == "news.php" $Item->url == "carslist.php")
{
//get the user level of logged in user
if(CurrentUserLevel() == -1)
{
return FALSE;//dont draw it
}
else
{
return TRUE;//draw it
}
}

if ($Item->url == "customers.php" )
{
//get the user level of logged in user
if(CurrentUserLevel() == 2)
{
return FALSE;//dont draw it
}
else
{
return TRUE;//draw it
}
}

return TRUE;
}


Re: Hiding menu items from userlevels

Posted: Fri Jan 26, 2018 5:23 am
by cdmak

Got it thanks, works now.

Thank You