Jump to content

Hiding a custom navbar (Hook) for non-signedin users


Recommended Posts

Hello,

I have built a hook to show a new navbar, but I want it to hide to not logged in members. Is this possible?

Thank you :)

 

My hook im using:

<?php

use WHMCS\View\Menu\Item as MenuItem;

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

   $primaryNavbar->addChild('Tools')
               ->setOrder(50);

   $primaryNavbar->getChild('Tools')
               ->addChild('Html Tester')
               ->setUri('/html.php')
               ->setOrder(1);

   $primaryNavbar->getChild('Tools')            
               ->addChild('Privacy Policy Generator')
               ->setUri('/privacypolicygenerator.php')
               ->setOrder(2);
   $primaryNavbar->getChild('Tools')            
               ->addChild('cPanel Backup Generator')
               ->setUri('/backup.php')
               ->setOrder(3);
});

 

Link to comment
Share on other sites

it's possible using Menu::context('client') the following code would work:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
   {
	
	// When no client logged in do nothing
	if (is_null(Menu::context('client'))){
		return;
	}
	
	// Client logged in then show our navbar

   $primaryNavbar->addChild('Tools')
               ->setOrder(50);

   $primaryNavbar->getChild('Tools')
               ->addChild('Html Tester')
               ->setUri('/html.php')
               ->setOrder(1);

   $primaryNavbar->getChild('Tools')            
               ->addChild('Privacy Policy Generator')
               ->setUri('/privacypolicygenerator.php')
               ->setOrder(2);
   $primaryNavbar->getChild('Tools')            
               ->addChild('cPanel Backup Generator')
               ->setUri('/backup.php')
               ->setOrder(3);
});

 

Link to comment
Share on other sites

Hi, 

Could you give an example of this? Say I want it to show:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
   {
	
	// When no client logged in do nothing
	if (is_null(Menu::context('client'))){
		return;
	}
	
	// Client logged in then show our navbar

   $primaryNavbar->addChild('Tools')
               ->setOrder(50);

   $primaryNavbar->getChild('Tools')
               ->addChild('Html Tester')
               ->setUri('/html.php')
               ->setOrder(1);

   $primaryNavbar->getChild('Tools')            
               ->addChild('Privacy Policy Generator')
               ->setUri('/privacypolicygenerator.php')
               ->setOrder(2);
   $primaryNavbar->getChild('Tools')            
               ->addChild('Website Builder')
               ->setUri('https://yvsse.com/builder')
               ->setOrder(4);
   $primaryNavbar->getChild('Tools')            
               ->addChild('cPanel Backup Generator')
               ->setUri('/backup.php')
               ->setOrder(4);
});

To only users on server "server32"?

Thank you.

Link to comment
Share on other sites

you can specify multiple server ids separated by comma

<?php

use WHMCS\View\Menu\Item as MenuItem;
use WHMCS\Database\Capsule;

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

	// When no client logged in do nothing
	if (is_null($client)){
		return;
	}
	
	// Specify multiple server ids separated by comma ","
	$serverIds = array(1, 2, 32);
    
    $getServices = Capsule::table("tblhosting")
    ->where("userid", $client->id)
    ->whereIn("server", $serverIds)
    ->count();
	
	// no services in the specified servers
	if ($getServices === 0){
		return;
	}

   $primaryNavbar->addChild('Tools')
               ->setOrder(50);

   $primaryNavbar->getChild('Tools')
               ->addChild('Html Tester')
               ->setUri('/html.php')
               ->setOrder(1);

   $primaryNavbar->getChild('Tools')            
               ->addChild('Privacy Policy Generator')
               ->setUri('/privacypolicygenerator.php')
               ->setOrder(2);
   $primaryNavbar->getChild('Tools')            
               ->addChild('Website Builder')
               ->setUri('https://yvsse.com/builder')
               ->setOrder(4);
   $primaryNavbar->getChild('Tools')            
               ->addChild('cPanel Backup Generator')
               ->setUri('/backup.php')
               ->setOrder(4);
});

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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