plusplushosting Posted February 23, 2019 Share Posted February 23, 2019 Hi there im trying to hide/remove the Networl status from the menu....but somehow im not getting it working. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Network Status'))) { $primaryNavbar->getChild('Network Status') ->removeChild('Network Status'); } }); Any idea where is my error? Thanx in advance! 0 Quote Link to comment Share on other sites More sharing options...
bear Posted February 23, 2019 Share Posted February 23, 2019 42 minutes ago, plusplushosting said: $primaryNavbar->getChild('Network Status') This middle line isn't needed, and the line after is missing the beginning: $primaryNavbar->removeChild('Network Status'); 1 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted February 23, 2019 Author Share Posted February 23, 2019 Thanx Bear! That worked half way...is working for non logged in users, once you login is showing the link in the menu 😞 0 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted February 23, 2019 Author Share Posted February 23, 2019 ok, got it working. Thanx! add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->getChild('Support') ->removeChild('Network Status'); } }); add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Network Status'))) { $primaryNavbar->removeChild('Network Status'); } }); 0 Quote Link to comment Share on other sites More sharing options...
bear Posted February 24, 2019 Share Posted February 24, 2019 2 hours ago, plusplushosting said: add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Network Status'))) { $primaryNavbar->removeChild('Network Status'); } }); This is the result I suggested, and what's "fixed" the menu. "remove the middle one, and you were missing the first part of the last line..." The top half of your hook (everything before the second "add_hook) isn't doing anything, I'd say. 0 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted February 24, 2019 Author Share Posted February 24, 2019 Thanx ! The first half is removing the item from the menu when the client is logged in, at least in my theme. I guess the second half work ok in the default six theme even when they are logged in. Thanx again Bear! 0 Quote Link to comment Share on other sites More sharing options...
bear Posted February 24, 2019 Share Posted February 24, 2019 How odd. I based my theme on six, and it doesn't show the support options at all in the main menu if they're not logged in, and the code I gave hides the network bits when they are. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 24, 2019 Share Posted February 24, 2019 13 hours ago, plusplushosting said: ok, got it working. not that it particularly matters, but you don't need two separate hooks like that - just move the second IF statement to after the first IF Statement in the first hook and you're done. 2 minutes ago, bear said: How odd. I based my theme on six, and it doesn't show the support options at all in the main menu if they're not logged in, and the code I gave hides the network bits when they are. @plusplushosting is right in what he says - now in theory the way he's doing might cause an error if there were another hook running that removed the Support/Network Status before this hook ran, but I guess it's highly unlikely that would occur (unless you had a lot of separate hooks and forget what they do & when they ran). 🙂 0 Quote Link to comment Share on other sites More sharing options...
bear Posted February 24, 2019 Share Posted February 24, 2019 (edited) Never mind. As long as it works for him. Edited February 24, 2019 by bear 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 24, 2019 Share Posted February 24, 2019 2 hours ago, bear said: How odd. I based my theme on six, and it doesn't show the support options at all in the main menu if they're not logged in, and the code I gave hides the network bits when they are. that's right - that support menu only shows for loggedin clients, but because they have a unique name, you don't need to check whether the client is logged in before removing it... ideally, you probably should do and apply other checks too, but in practice, and because it's a default menu, you don't usually *need* to. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.