Jump to content

Change menu Navbar


kenchiro

Recommended Posts

it's basically a similar way - as you know, when you want to remove a navbar item (e.g "Home") for a client who IS logged in, you would do this...

 

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $client = Menu::context('client');
   if (!is_null($client) and (!is_null($primaryNavbar->getChild('Home')))) {
           $primaryNavbar->removeChild('Home');
   }
});

now if you want to remove the "Home" navbar item when the client is NOT logged in, you would do the following...

 

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $client = Menu::context('client');
   if (is_null($client) and (!is_null($primaryNavbar->getChild('Home')))) {
           $primaryNavbar->removeChild('Home');
   }
});

note that the only difference between the two is the ! before is_null($client) - the first hook checks to see if the client is logged in; the second checks to see that they are not. :idea:

 

when you become familiar with the navbars, there is a simpler way to modify most of them as they will only exist in one navbar and not both (logged in and not logged in)... e.g when not logged in (as in your screenshot), there is a navbar item called "Announcements" - if you want to remove it, you can use...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Announcements'))) {
           $primaryNavbar->removeChild('Announcements');
   }
});

note that we aren't checking whether the client is logged in or not - we don't need to - the "Announcements" navbar item only exists with that name in the not logged in navbar; there is an "Announcements" link in the navbar when logged in, but it's a child of "Support" and so would require another hook to remove it - in short, the above code removes the "Announcements" link from the non-client navbar, but doesn't affect the link in the client navbar.

 

however, until you are familiar with the navbars, it's probably safer for you to check, in the hook, whether the client is logged in or not. :idea:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated