Hiding admin menu items in Opencart

Hiding admin menu items in Opencart

How to hide the admin menu items in OpenCart

There are several reasons you may want to do this that we have found
Hide items from users that do not have viewing access privileges.
Hide unwanted items such as Openbay which now ships with opencart.
Hide the Help menu from opencart or re-direct to another location such as your own video directory or youtube tutorial page

While recently working on a customers OpenCart website, I noticed that admin menu items were still visible even if the admin user did not have viewing access privileges. There are a few great little vqmods available in the extension directory to resolve this which i’m sure will work for most users.
However i found a slight annoyance that seems to have been caused by the openbay addition, when users do not have permissions to openbay they are getting the restricted message on some of the pages they do have access to like product and category edit pages and the order history tab.

I could have a deep look into this and resolved the problem in the code but as the module is not going to be used by the customer the easiest and quickest solution i found for this is to leave the permissions accessible and remove the menu item for openbay, thus de-cluttering the menu and removing access to the module.

To do this navigate to /admin/view/template/common/ and open your header.tpl file in your favourite text editor.

You will see in this file the OpenCart eCommerce structure uses MVC (Model-View-Controller), so the menu is contained in the file header.tpl as an unordered list. Using the existing OpenCart function hasPermission() a check is performed on each <li>to determine if the admin user has viewing (access) privileges. If the user has access permission then continue to the if statement to show the menu item. Otherwise ignore it and move on.

So to remove it from the menu simply comment out the list items, in the case of openbay you will find the line

<li><a><?php echo $text_openbay_extension; ?></a>

and you can comment like so

<!--<li><a><?php echo $text_openbay_extension; ?></a> -->

Leave a Reply