kacm Posted January 25, 2016 Share Posted January 25, 2016 Hi I got this code from http://docs.whmcs.com/Editing_Client_Area_Menus and i put this into hook file. Everything works fine while I am not logged in. When I log in into customer account i got 500 internal error. Anny issues? <?php add_hook('ClientAreaNavbars', 1, function () { // Get the current navigation bars. $primaryNavbar = Menu::primaryNavbar(); $secondaryNavbar = Menu::secondaryNavbar(); // Save the "Contact Us" link and remove it from the primary navigation bar. $contactUsLink = $primaryNavbar->getChild('Contact Us'); $primaryNavbar->removeChild('Contact Us'); // Add the email sales link to the link's drop-down menu. $contactUsLink->addChild('email-sales', array( 'label' => 'Email our sales team', 'uri' => 'sales@my-awesome-company.com', 'order' => 1, 'icon' => 'fa-diamond', )); // Add the call us link to the link's drop-down menu. $contactUsLink->addChild('call-us', array( 'label' => 'Call us', 'uri' => 'tel:+18005551212', 'order' => 2, 'icon' => 'fa-mobile', )); // Add the map to the company to the link's drop-down menu. $contactUsLink->addChild('map', array( 'label' => '123 Main St. AnyTown, TX 11223, USA', 'uri' => 'https:\/\/maps.google.com/maps/place/some-map-data', 'order' => 3, 'icon' => 'fa-map-marker', )); // Add the link and its drop-down children to the secondary navigation bar. $secondaryNavbar->addChild($contactUsLink); // Make sure the contact us link appears as the first item in the // secondary navigation bar. $contactUsLink->moveToFront(); }); 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted January 26, 2016 Share Posted January 26, 2016 With add_hook('ClientAreaNavbars', 1, function () { Double check to see if this will help add_hook('ClientAreaNavbars', 1, function ()) // added a closing ")" { 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 26, 2016 Share Posted January 26, 2016 the incorrect assumption is that the example hook codes in the documentation work... they partially do, but not 100% the important point to always remember with these navbar hooks is that you shouldn't add/remove/modify an existing element, unless you have first checked to see that it exists... if it exists, the above hook will work; if it doesn't (e.g you're logged in a client and there is no existing "Contact Us" button), the hook will fail. an alternative way to do this would be to use both primary and secondary navbar hooks in the same file - firstly removing the contact us link from the primary navbar (after checking it exists); and then adding the contact us link to the secondary navbar and adding the child links beneath it. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Contact Us'))) { $primaryNavbar->removeChild('Contact Us'); } }); add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar) { // Add Contact Us to the secondary navbar. $secondaryNavbar->addChild('Contact Us'); // Add the email sales link to the link's drop-down menu. $secondaryNavbar->getChild('Contact Us') ->addChild('email-sales', array( 'label' => 'Email our sales team', 'uri' => 'sales@my-awesome-company.com', 'order' => 1, 'icon' => 'fa-envelope-o', )); // Add the call us link to the link's drop-down menu. $secondaryNavbar->getChild('Contact Us') ->addChild('call-us', array( 'label' => 'Call us', 'uri' => 'tel:+18005551212', 'order' => 2, 'icon' => 'fa-mobile', )); // Add the map to the company to the link's drop-down menu. $secondaryNavbar->getChild('Contact Us') ->addChild('map', array( 'label' => '123 Main St. AnyTown, TX 11223, USA', 'uri' => 'https:\/\/maps.google.com/maps/place/some-map-data', 'order' => 3, 'icon' => 'fa-map-marker', )); }); I suppose to be strictly safe, you should check before adding each child that its parent exists, but in the above hook that shouldn't really be necessary as the hook creates the parent. 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.