Jump to content

hooks on primary navigation in client area


dakeister

Recommended Posts

<?php

 

use WHMCS\View\Menu\Item as MenuItem;

 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)

{

$client = Menu::context('client');

 

// only add menu item when no client logged in

if (is_null($client)) {

$primaryNavbar->addChild('Example')

->setUri('https://www.example.com/')

->setOrder(100);

}

});

I have used the above code to add links to our control panel which works Ok but I would like to make a drop down list under Client Portals for Websitepanel, webmail, and web stats. New to PHP any help with code would be extremely grateful.

Link to comment
Share on other sites

Thanks for the help Brian but I tried that it didn't work just get a blank page.

I did this code first;

 

<?php

 

use WHMCS\View\Menu\Item as MenuItem;

 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)

{

$client = Menu::context('client');

 

// only add menu item when no client logged in

if (is_null($client)) {

$primaryNavbar->addChild('Client Portals')

->setOrder(100);

}

});

 

And saved it as ClientPortal.php which gives me the Tab Client Portals. The page will load and the nave bar is present.

 

Then I added this code to ClientPortal1.php;

 

<?php

 

use WHMCS\View\Menu\Item as MenuItem;

 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)

{

$primaryNavbar->getChild('Client Portals')

->addChild('Remote Support', array(

'label' => 'Remote Support',

'uri' => 'http://www.mdcdnn.net:8040',

'order' => '200',

));

$primaryNavbar->getChild('Client Portals')

->addChild('Divider', array(

'order' => '300',

))

->setClass('nav-divider');

$primaryNavbar->getChild('Client Portals')

->addChild('Web Mail', array(

'label' => 'Web Mail',

'uri' => 'http://webmail.mdcdnn.net',

'order' => '400',

));

$primaryNavbar->getChild('Client Portals')

->addChild('Divider', array(

'order' => '500',

))

->setClass('nav-divider');

$primaryNavbar->getChild('Client Portals')

->addChild('Web Stats', array(

'label' => 'Web Stats',

'uri' => 'http://stats.mdcdnn.net',

'order' => '600',

));

}

});

 

Which just gives me a blank page. I have also removed the divider tags which gives me the same results.

Link to comment
Share on other sites

Hi,

 

Thanks for the help Brian but I tried that it didn't work just get a blank page.

a blank page? welcome to coding WHMCS hooks. :)

 

i'm unsure why you're trying to use two separate hooks to do this - I guess you could if you really needed to, but certainly not the way you're trying it! :idea:

 

what I would do is just edit clientportal.php and add the code below (and delete clientportal1.php)...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
$client = Menu::context('client');

// only add menu item when no client logged in

   if (is_null($client)) {
       $primaryNavbar->addChild('Client Portals')
                   ->setOrder(100);
       $primaryNavbar->getChild('Client Portals')
                   ->addChild('Remote Support', array(
                   'label' => 'Remote Support',
                   'uri' => 'http://www.mdcdnn.net:8040',
                   'order' => '200',
                   ));
       $primaryNavbar->getChild('Client Portals')
                   ->addChild('Divider1', array(
                   'order' => '300',
                   ))
                   ->setClass('nav-divider');
       $primaryNavbar->getChild('Client Portals')
                   ->addChild('Web Mail', array(
                   'label' => 'Web Mail',
                   'uri' => 'http://webmail.mdcdnn.net',
                   'order' => '400',
                   ));
       $primaryNavbar->getChild('Client Portals')
                   ->addChild('Divider2', array(
                   'order' => '500',
                   ))
                   ->setClass('nav-divider');
       $primaryNavbar->getChild('Client Portals')
                   ->addChild('Web Stats', array(
                   'label' => 'Web Stats',
                   'uri' => 'http://stats.mdcdnn.net',
                   'order' => '600',
                   ));
   }
});

this should now show the dropdown to anyone who is *not* logged in.

 

also, it's worth remembering that children names must be unique - so you can't have two children called 'Divider', so in the above code, i've numbered them 1 & 2 to make their names different.

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