Jump to content

menu hook throws error when logging out


Recommended Posts

V6.01

 

I have a hook menu.php

 

It is working to do what I wanted, add an item to the support menu and remove the downloads item. Cool!

 

But when logging out from the client area it throws an error.

 

"Fatal error: Call to a member function addChild() on a non-object in /home/steved/public_html/includes/hooks/menu.php on line 9"

 

This implies that when someone is logging out and logout.php is being loaded, it is calling the menu hook. Reloading logout.php then redirects to index.php

 

When logout.php is being called, by that time the $ca->isLoggedIn() flag should be false shouldn't it? So it shouldn't even see the code throwing the error.

 

Or am I completely missing the point somewhere?

 

$ca = new WHMCS_ClientArea();

use WHMCS\View\Menu\Item as MenuItem;

if ($ca->isLoggedIn()) {

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar){
/** Add Create Ticket to the Support Menu **/ 
$primaryNavbar->getChild('Support')->addChild('Firewall Management', array(
'label' => 'Open a Ticket',
'uri' => 'https://domain.com/submitticket.php',
'order' => '1',
));
});

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
if (!is_null($primaryNavbar->getChild('Support'))) {
$primaryNavbar->getChild('Support')->removeChild('Downloads');
}
});

}

Link to comment
Share on other sites

this come from custom page:

$ca = new WHMCS_ClientArea(); 
$ca->isLoggedIn();

 

and the rest is action hook related, your code can be something like this:

 

<?php

use WHMCS\View\Menu\Item as MenuItem; 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar){ 
if (isset($_SESSION['uid'])){
   /** Add Create Ticket to the Support Menu **/  
   $primaryNavbar->getChild('Support')->addChild('Firewall Management', array( 
   'label' => 'Open a Ticket', 
   'uri' => 'https://domain.com/submitticket.php', 
   'order' => '1', 
   ));
}
}); 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) 
{ 
if (!is_null($primaryNavbar->getChild('Support'))) { 
   $primaryNavbar->getChild('Support')->removeChild('Downloads'); 
} 
}); 

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.

×
×
  • 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