techdruid Posted September 4, 2015 Share Posted September 4, 2015 Hello, I used to have a custom php section when PHP was enabled in the Smarty templates for removing the affiliate menu item for non-affiliates. With the upgrade to WHMCS version 6, php code is disabled by default. I'm inclined to follow the advice and not make PHP calls directly from the smarty templates. So what I'm looking at as an alternative is adding a ClientAreaNavbars hook, and using the "primaryNavbar->removeChild('Affiliates')" option to remove the menu item. However, what I'm struggling with is how do I write the code to determine if the the current user is an affiliate or not? Do I have to custom code getting to the database? Or, are there variables or functions available to me within a hook function where I can grab this information? I tried using the "use Illumiate\Database\Capsule\Manager as Capsule" library, but that doesn't seem to work within the function. I've got the following code to work to remove the menu item for EVERYONE. Now I just need to narrow it down to only remove it for non-affiliates. Any advice would be much appreciated. <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); function MY_navbar_mods() { $primaryNavbar = Menu::primaryNavbar(); $primaryNavbar->removeChild('Affiliates'); } add_hook("ClientAreaNavbars",1,"MY_navbar_mods"); ?> 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 4, 2015 Share Posted September 4, 2015 try the following... <?php use WHMCS\View\Menu\Item as MenuItem; add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) { $client = Menu::context('client'); $affiliate = $client->affiliate; if (is_null($affiliate)) { if (!is_null($primaryNavbar->getChild('Affiliates'))) { $primaryNavbar->removeChild('Affiliates'); } } }); it should remove the link to non-affiliates (logged in or not), but show the link to affiliates. 0 Quote Link to comment Share on other sites More sharing options...
techdruid Posted September 4, 2015 Author Share Posted September 4, 2015 Brilliant! That worked. Thank you Brian!! 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.