Jump to content

Add menu only for logged in users!


dbbrito

Recommended Posts

Friends, I made the code below to add a menu on whmcs, but I would like it to be available only to logged in customers, and the way it is configured it is also shown to non-logged customers.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar)
   {

   $secondarySidebar->addChild('Servers')
               ->setOrder(1);

   $secondarySidebar->getChild('Servers')
               ->addChild('Show in')
               ->setUri('*****.html')
               ->setOrder(1);

   $secondarySidebar->getChild('VoIP Enterprise')            
               ->addChild('Show out')
               ->setUri('******.html')
               ->setOrder(2);
});

 

Thank you all

Link to comment
Share on other sites

10 minutes ago, dbbrito said:

Friends, I made the code below to add a menu on whmcs, but I would like it to be available only to logged in customers, and the way it is configured it is also shown to non-logged customers.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {
	
	$client = Menu::context('client');
	if (!is_null($client) && is_null($secondarySidebar->getChild('Servers'))) {
		$secondarySidebar->addChild('Servers')->setOrder(1);
	}
	if (!is_null($client) && !is_null($secondarySidebar->getChild('Servers'))) {
		$secondarySidebar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1);
	}
	if (!is_null($client) && !is_null($secondarySidebar->getChild('VoIP Enterprise'))) {
		$secondarySidebar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2);
	}
}); 

 

Link to comment
Share on other sites

  • 2 weeks later...
On 9/26/2020 at 9:25 AM, brian! said:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {
	
	$client = Menu::context('client');
	if (!is_null($client) && is_null($secondarySidebar->getChild('Servers'))) {
		$secondarySidebar->addChild('Servers')->setOrder(1);
	}
	if (!is_null($client) && !is_null($secondarySidebar->getChild('Servers'))) {
		$secondarySidebar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1);
	}
	if (!is_null($client) && !is_null($secondarySidebar->getChild('VoIP Enterprise'))) {
		$secondarySidebar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2);
	}
}); 

 

How to use this same menu in primaryNavbar?
What do I need to change?

Thanks

Link to comment
Share on other sites

20 hours ago, dbbrito said:

How to use this same menu in primaryNavbar?
What do I need to change?

all that you should need to do is change references of secondarysidebar to primarynavbar and change the hook point used - the rest of the code stays the same (though you might need to change the setOrder value on the first if statement depending on where you want to display it.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primarynavbar) {
	
	$client = Menu::context('client');
	if (!is_null($client) && is_null($primarynavbar->getChild('Servers'))) {
		$primarynavbar->addChild('Servers')->setOrder(1);
	}
	if (!is_null($client) && !is_null($primarynavbar->getChild('Servers'))) {
		$primarynavbar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1);
	}
	if (!is_null($client) && !is_null($primarynavbar->getChild('VoIP Enterprise'))) {
		$primarynavbar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2);
	}
});
Link to comment
Share on other sites

12 hours ago, brian! said:

all that you should need to do is change references of secondarysidebar to primarynavbar and change the hook point used - the rest of the code stays the same (though you might need to change the setOrder value on the first if statement depending on where you want to display it.


<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primarynavbar) {
	
	$client = Menu::context('client');
	if (!is_null($client) && is_null($primarynavbar->getChild('Servers'))) {
		$primarynavbar->addChild('Servers')->setOrder(1);
	}
	if (!is_null($client) && !is_null($primarynavbar->getChild('Servers'))) {
		$primarynavbar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1);
	}
	if (!is_null($client) && !is_null($primarynavbar->getChild('VoIP Enterprise'))) {
		$primarynavbar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2);
	}
});

Brian, taking the example below, how can only the "Servers" Menu appear for everyone without logging in, and the "Show in" and "Show out" items appear only for logged in customers? Thanks

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primarynavbar) {
	
	$client = Menu::context('client');
	if (!is_null($client) && is_null($primarynavbar->getChild('Servers'))) {
		$primarynavbar->addChild('Servers')->setOrder(1);
	}
	if (!is_null($client) && !is_null($primarynavbar->getChild('Servers'))) {
		$primarynavbar->getChild('Servers')->addChild('Show in')->setUri('*****.html')->setOrder(1);
	}
	if (!is_null($client) && !is_null($primarynavbar->getChild('VoIP Enterprise'))) {
		$primarynavbar->getChild('VoIP Enterprise')->addChild('Show out')->setUri('******.html')->setOrder(2);
	}
});
Link to comment
Share on other sites

9 hours ago, dbbrito said:

Brian, taking the example below, how can only the "Servers" Menu appear for everyone without logging in, and the "Show in" and "Show out" items appear only for logged in customers?

in the above example, if you wanted a menu item to appear all the time, then you couldn't check if they were a client...

if (is_null($primarynavbar->getChild('Servers'))) {

the second and third menu child should only be shown for logged-in users - though in practice, that 3rd one (VoIP) wouldn't be shown unless there is another hook somewhere creating it.

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