dbbrito Posted September 26, 2020 Share Posted September 26, 2020 Friends, I made the code below to add a menu on whmcs, but I would like it to be available only to logged in customers, and the way it is configured it is also shown to non-logged customers. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $secondarySidebar->addChild('Servers') ->setOrder(1); $secondarySidebar->getChild('Servers') ->addChild('Show in') ->setUri('*****.html') ->setOrder(1); $secondarySidebar->getChild('VoIP Enterprise') ->addChild('Show out') ->setUri('******.html') ->setOrder(2); }); Thank you all 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 26, 2020 Share Posted September 26, 2020 10 minutes ago, dbbrito said: Friends, I made the code below to add a menu on whmcs, but I would like it to be available only to logged in customers, and the way it is configured it is also shown to non-logged customers. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $client = Menu::context('client'); if (!is_null($client) && is_null($secondarySidebar->getChild('Servers'))) { $secondarySidebar->addChild('Servers')->setOrder(1); } if (!is_null($client) && !is_null($secondarySidebar->getChild('Servers'))) { $secondarySidebar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1); } if (!is_null($client) && !is_null($secondarySidebar->getChild('VoIP Enterprise'))) { $secondarySidebar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2); } }); 0 Quote Link to comment Share on other sites More sharing options...
Magicklug Posted September 27, 2020 Share Posted September 27, 2020 How to use it? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 27, 2020 Share Posted September 27, 2020 41 minutes ago, Magicklug said: How to use it? you create a .php file in /includes/hooks, copy & paste the code into it and save. ✔️ 1 Quote Link to comment Share on other sites More sharing options...
tashawummery Posted September 29, 2020 Share Posted September 29, 2020 This is quite useful, thank you. 🙂 0 Quote Link to comment Share on other sites More sharing options...
Magicklug Posted October 13, 2020 Share Posted October 13, 2020 On 9/27/2020 at 8:39 PM, brian! said: you create a .php file in /includes/hooks, copy & paste the code into it and save. ✔️ Got it Brian thanks! 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted October 15, 2020 Author Share Posted October 15, 2020 On 9/26/2020 at 9:25 AM, brian! said: <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $client = Menu::context('client'); if (!is_null($client) && is_null($secondarySidebar->getChild('Servers'))) { $secondarySidebar->addChild('Servers')->setOrder(1); } if (!is_null($client) && !is_null($secondarySidebar->getChild('Servers'))) { $secondarySidebar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1); } if (!is_null($client) && !is_null($secondarySidebar->getChild('VoIP Enterprise'))) { $secondarySidebar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2); } }); How to use this same menu in primaryNavbar? What do I need to change? Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 16, 2020 Share Posted October 16, 2020 20 hours ago, dbbrito said: How to use this same menu in primaryNavbar? What do I need to change? all that you should need to do is change references of secondarysidebar to primarynavbar and change the hook point used - the rest of the code stays the same (though you might need to change the setOrder value on the first if statement depending on where you want to display it. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primarynavbar) { $client = Menu::context('client'); if (!is_null($client) && is_null($primarynavbar->getChild('Servers'))) { $primarynavbar->addChild('Servers')->setOrder(1); } if (!is_null($client) && !is_null($primarynavbar->getChild('Servers'))) { $primarynavbar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1); } if (!is_null($client) && !is_null($primarynavbar->getChild('VoIP Enterprise'))) { $primarynavbar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2); } }); 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted October 17, 2020 Author Share Posted October 17, 2020 12 hours ago, brian! said: all that you should need to do is change references of secondarysidebar to primarynavbar and change the hook point used - the rest of the code stays the same (though you might need to change the setOrder value on the first if statement depending on where you want to display it. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primarynavbar) { $client = Menu::context('client'); if (!is_null($client) && is_null($primarynavbar->getChild('Servers'))) { $primarynavbar->addChild('Servers')->setOrder(1); } if (!is_null($client) && !is_null($primarynavbar->getChild('Servers'))) { $primarynavbar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1); } if (!is_null($client) && !is_null($primarynavbar->getChild('VoIP Enterprise'))) { $primarynavbar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2); } }); Brian, taking the example below, how can only the "Servers" Menu appear for everyone without logging in, and the "Show in" and "Show out" items appear only for logged in customers? Thanks <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primarynavbar) { $client = Menu::context('client'); if (!is_null($client) && is_null($primarynavbar->getChild('Servers'))) { $primarynavbar->addChild('Servers')->setOrder(1); } if (!is_null($client) && !is_null($primarynavbar->getChild('Servers'))) { $primarynavbar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1); } if (!is_null($client) && !is_null($primarynavbar->getChild('VoIP Enterprise'))) { $primarynavbar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2); } }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 17, 2020 Share Posted October 17, 2020 9 hours ago, dbbrito said: Brian, taking the example below, how can only the "Servers" Menu appear for everyone without logging in, and the "Show in" and "Show out" items appear only for logged in customers? in the above example, if you wanted a menu item to appear all the time, then you couldn't check if they were a client... if (is_null($primarynavbar->getChild('Servers'))) { the second and third menu child should only be shown for logged-in users - though in practice, that 3rd one (VoIP) wouldn't be shown unless there is another hook somewhere creating it. 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.