Jump to content

Add primary menu item problem


rickybsb

Recommended Posts

Hi experts, 

i´m trying to add item to primary menu, but didn´t show

code


<?php
#adding Menu Item to primaryNavbar
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
 if (!is_null($client)) {
    $primaryNavbar->addChild('UnBlock IP')
        ->setUri('index.php?m=unblockip')
        ->setOrder(70);
}
});
 

 

but when i use without restriction, thus not requiring user to be athenticated, it works


<?php
#adding Menu Item to primaryNavbar
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
 
    $primaryNavbar->addChild('UnBlock IP')
        ->setUri('index.php?m=unblockip')
        ->setOrder(70);

});
 

what am i doing wrong? 

 

 

Link to comment
Share on other sites

On 07/01/2019 at 19:08, rickybsb said:

what am i doing wrong? 

the problem with the first hook is that you're checking the status of $client, but never defining what $client is - so that if statement is never valid and hence the link is not added.

<?php
#adding Menu Item to primaryNavbar
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
	$client = Menu::context('client');
	if (!is_null($client)) {
		$primaryNavbar->addChild('UnBlock IP')
			->setUri('index.php?m=unblockip')
			->setOrder(70);
	}
});

the above will add a menu link to a client's menu when they are logged in - if they are not logged in, the link will not be added.

Link to comment
Share on other sites

5 hours ago, brian! said:

the problem with the first hook is that you're checking the $status of $client, but never defining what $client is - so that if statement is never valid and so the link is not added.


<?php
#adding Menu Item to primaryNavbar
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
	$client = Menu::context('client');
	if (!is_null($client)) {
		$primaryNavbar->addChild('UnBlock IP')
			->setUri('index.php?m=unblockip')
			->setOrder(70);
	}
});

the above will add a menu link to a client's menu when they are logged in - if they are not logged in, the link will not be added.

worked like a charm

thanks, man!!! 

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