Jump to content

How do I remove the affiliate menu for non affiliates?


techdruid

Recommended Posts

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");

?>

Link to comment
Share on other sites

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. :idea:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated