Filozof Posted November 28, 2018 Share Posted November 28, 2018 Hi, community! 🙂 I have a questions about hooks. So, I've been using some hooks to "hide" some menu/submenu items and sidebars in client area. I added all the hooks in one file (example: custom_hooks.php) and placed in /includes/hooks directory. And that works fine for some time and then it's simply stop working and all menus/submenus and sidebars reappear again. I also tried to create separate .php file for each hook and upload it to the same location. Issue is the same: it stops working and all the elements reappear in client area. Here's an example of the code used: <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $secondarySidebar->removeChild('Choose Currency'); }); add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $secondarySidebar->removeChild('Actions'); }); add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $secondarySidebar->removeChild('Client Shortcuts'); }); add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) { $primarySidebar->removeChild('My Invoices Summary'); }); add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) { $primarySidebar->removeChild('My Invoices Status Filter'); }); add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) { $secondarySidebar->removeChild('Billing'); }); add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->getChild('Support')->removeChild('Downloads'); } }); 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('Billing'))) { $primaryNavbar->getChild('Billing')->removeChild('My Quotes'); } }); Is this wrong or issue is something else? Thanks for your help! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 30, 2018 Share Posted November 30, 2018 On 28/11/2018 at 17:53, Filozof said: Is this wrong or issue is something else? it's wrong - specifically there is one golden rule that you need to remember with navbar/sidebar hooks - you always need to check that the child you are removing/modifying actually exists before you try to do anything to it... otherwise, they will only work on the pages where those children exist.. anywhere else and you might start seeing errors. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar) { if (!is_null($primarySidebar->getChild('My Invoices Status Filter'))) { $primarySidebar->removeChild('My Invoices Status Filter'); } if (!is_null($primarySidebar->getChild('My Invoices Summary'))) { $primarySidebar->removeChild('My Invoices Summary'); } }); add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) { if (!is_null($secondarySidebar->getChild('Actions'))) { $secondarySidebar->removeChild('Actions'); } if (!is_null($secondarySidebar->getChild('Billing'))) { $secondarySidebar->removeChild('Billing'); } if (!is_null($secondarySidebar->getChild('Choose Currency'))) { $secondarySidebar->removeChild('Choose Currency'); } if (!is_null($secondarySidebar->getChild('Client Shortcuts'))) { $secondarySidebar->removeChild('Client Shortcuts'); } }); add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->getChild('Support') ->removeChild('Downloads') ->removeChild('Network Status'); } if (!is_null($primaryNavbar->getChild('Billing'))) { $primaryNavbar->getChild('Billing') ->removeChild('My Quotes'); } }); technically, we should be checking those navbar children exist before removing them, but as long as you don't have other hooks trying to remove them before this hook runs, it shouldn't matter. 0 Quote Link to comment Share on other sites More sharing options...
Filozof Posted December 6, 2018 Author Share Posted December 6, 2018 @brian! tnx for reply! I did figure this out in the meantime and also the issue was with .tpl file owner in the Linux filesystem. 🙂 Stupid error, byt hey... 😄 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.