mauwiks Posted January 22, 2019 Share Posted January 22, 2019 Hi there, I'm new to WHMCS and would like to get some guidelines how to setup a hook or any straight-forward direction how to edit the label of my "Knowledgebase" primary and secondary navigations into FAQs? (instead of Knowledgebase). I would also like to add a new external link for the same navs as above which I will label as my official "Knowledgebase". Modifications should result into: 1. WHMCS Knowledgebase edited label into FAQs 2. Added new Knowledgebase external link Thank you for the further help. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 22, 2019 Share Posted January 22, 2019 14 hours ago, Mauwiks said: I'm new to WHMCS and would like to get some guidelines how to setup a hook or any straight-forward direction how to edit the label of my "Knowledgebase" primary and secondary navigations into FAQs? (instead of Knowledgebase). there are two ways - either use a hook, or if you only want to change the label of a default navbar/sidebar, you can use a Language Override... though you'd have to add an override for each language that you want to change the label for. so if wanting to use an override.. $_LANG['knowledgebasetitle'] = "Brian's FAQs"; 15 hours ago, Mauwiks said: I would also like to add a new external link for the same navs as above which I will label as my official "Knowledgebase". you need to decide where that link is going to be (navbar and/or sidebar), and whether the user needs to be logged in or not to see the new link - the answers to those questions will determine the required code. the Navbar Cheatsheet documentation may be of help to you, but there are plenty of similar working navbar examples posted in the forums... if you can't figure it out, then you ask for specific help. as an example, if you wanted to change the links on the existing knowledgebase navbar./sidebar links, then you could use the hook posted in the thread below... 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 22, 2019 Author Share Posted January 22, 2019 1 hour ago, brian! said: there are two ways - either use a hook, or if you only want to change the label of a default navbar/sidebar, you can use a Language Override... though you'd have to add an override for each language that you want to change the label for. so if wanting to use an override.. $_LANG['knowledgebasetitle'] = "Brian's FAQs"; 2 Thank you very much for your response. Much appreciated. I would prefer what is easier and cannot be overridden by an upgrade. 1 hour ago, brian! said: you need to decide where that link is going to be (navbar and/or sidebar), and whether the user needs to be logged in or not to see the new link - the answers to those questions will determine the required code. Both Navbar and sidebar, and I want everyone can have access to it whether they are logged in or not. Please let me know if you could give me some coded sample 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 23, 2019 Share Posted January 23, 2019 21 hours ago, Mauwiks said: I would prefer what is easier and cannot be overridden by an upgrade. neither using language overrides or hooks should get overwritten during an upgrade. 21 hours ago, Mauwiks said: Both Navbar and sidebar, and I want everyone can have access to it whether they are logged in or not. Please let me know if you could give me some coded sample the following hook should work... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Knowledgebase'))) { $primaryNavbar->getChild('Knowledgebase')->setLabel('FAQs'); $primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('http://www.google.com')->setOrder(30); } if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->getChild('Support')->getChild('Knowledgebase')->setLabel('FAQs'); $primaryNavbar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('http://www.google.com')->setOrder(30); } }); add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) { if (!is_null($secondarySidebar->getChild('Support'))) { $secondarySidebar->getChild('Support')->getChild('Knowledgebase')->setLabel('FAQs'); $secondarySidebar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('http://www.google.com')->setOrder(30)->setIcon('far fa-books'); } }); so screenshots below show what the navbar should look like for non-logged in users, logged in clients and the sidebar... 2 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 23, 2019 Author Share Posted January 23, 2019 You're a lifesaver! Thank you very much for this useful information and the time... If you will ever need my help further, please contact me at <removed> 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 23, 2019 Author Share Posted January 23, 2019 I will try it now but I need to finish my issues with updating the software... Thank you once again! 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 23, 2019 Author Share Posted January 23, 2019 I uploaded a .php file into /includes/hooks on my whmcs document root but it doesn't work. Is there something I've missed? 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 23, 2019 Author Share Posted January 23, 2019 It worked now! Thanks! I just had a typo error from the code 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 24, 2019 Author Share Posted January 24, 2019 Everything worked well but I decided to do the language overrides (changed the Knowledgebase text to FAQs) and then add a new menu using hooks function but my site returns an error after that: I followed this https://docs.whmcs.com/Client_Area_Navigation_Menus_Cheatsheet#Adding_a_Menu_Item and then changed from your code to this: ---------- <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle')) ->setURI('https://kindtechgroup.net/support') ->setOrder(30); } if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle')) ->setURI('https://kindtechgroup.net/support')->setOrder(30); } }); add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) { if (!is_null($secondarySidebar->getChild('Support'))) { $secondarySidebar->getChild('Support')->addChild('kb2') ->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support') ->setOrder(30)->setIcon('far fa-books'); } }); I know something's wrong with my code. Please enlighten me 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 24, 2019 Share Posted January 24, 2019 12 hours ago, Mauwiks said: I know something's wrong with my code. Please enlighten me this should work.. <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { $client = Menu::context("client"); if (!$client) { $primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30); } if (!is_null($primaryNavbar->getChild('Support'))) { $primaryNavbar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30); } }); add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) { if (!is_null($secondarySidebar->getChild('Support'))) { $secondarySidebar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30)->setIcon('far fa-books'); } }); i'm assuming that you want non logged-in users see it on the navbar and logged-in clients to see it within the support dropdown on the navbar - if so the above should do it... if you want everyone to see the KB link in the same place on the navbar,whether logged in or not, <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { $primaryNavbar->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30); }); add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) { if (!is_null($secondarySidebar->getChild('Support'))) { $secondarySidebar->getChild('Support')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('https://kindtechgroup.net/support')->setOrder(30)->setIcon('far fa-books'); } }); 2 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 24, 2019 Author Share Posted January 24, 2019 I restored my installation because of the error. And I decided to keep the "knowledgebase" term instead and just add a new Menu as follows: PrimaryNavMenu and SecondaryNavMenu for (logged in users or not): 1. Add new "Support" Menu with an external link to https://kindtechgroup.net/support 2. Under the Support SubMenu, add a new Menu with the same link labeled as Support Center 3. Add "Support Center" under the Support (SideBar Header) but change the label of the (SideBar Header) to "Support Panel" If this is too much, can you give me a hint for #1 instead? Thanks further. I've searched for a while but it doesn't fit my needs 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 24, 2019 Author Share Posted January 24, 2019 Actually, instead of "Support Panel", I think it's better to rename it with "Resources" and as well as the "Support" (Parent Menu) in the client area when users are logged in 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 25, 2019 Share Posted January 25, 2019 1. is basically going to be... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (is_null($primaryNavbar->getChild('Support Center'))) { $primaryNavbar->addChild('Support Center')->setOrder(30); $primaryNavbar->getChild('Support Center')->addChild('kb2')->setLabel(Lang::trans('knowledgebasetitle'))->setURI('http://www.google.com'); } }); 3. is going to be a label change using either Language Overrides.... $_LANG['navsupport'] = "Support"; changing that string will rename the parent of both the sidebar and the loggedin support navbar parent menu. or setLabel... the other hooks will show you how to do that. 1 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted January 25, 2019 Author Share Posted January 25, 2019 Thank so much....... 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted February 13, 2019 Author Share Posted February 13, 2019 How do we add another external link like Shop to the NavMenu in the client area which should probably be here? I tried it once but I needed to restore because I got some error. 😞 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 13, 2019 Share Posted February 13, 2019 17 minutes ago, Mauwiks said: How do we add another external link like Shop to the NavMenu in the client area which should probably be here? <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { if (!is_null($primaryNavbar->getChild('Store'))) { $primaryNavbar->getChild('Store')->addChild('newproduct1')->setLabel('My New Product Link')->setURI('http://www.google.com')->setOrder(25); } }); i'm assuming that you didn't want to get rid of the divider that you highlighted - though if you did, then that's just uses a removeChild... the same as removing any other child item. the value within ->setOrder determines where the new link will be added... if you made it 1, it would be before "Browse All"; if you made it 1000, it would likely be at the bottom of the dropdown... anywhere between just requires you to enter different values until you have it in the position that you want it. 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted February 13, 2019 Author Share Posted February 13, 2019 Great, thanks! I just want it to be below the browse all. Modifying the code above such as setorder shall work right? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 13, 2019 Share Posted February 13, 2019 Just now, Mauwiks said: I just want it to be below the browse all. Modifying the code above such as setorder shall work right? yeah, just play with the value... if memory serves, anything over 10 should put the link after browse all. 0 Quote Link to comment Share on other sites More sharing options...
mauwiks Posted February 13, 2019 Author Share Posted February 13, 2019 I will update you though. Thanks much! 0 Quote Link to comment Share on other sites More sharing options...
Md Rasel Khan Posted October 11, 2021 Share Posted October 11, 2021 @brian! How set the order to last? 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.