Jump to content

500 Error after creating sidebar hook from WHMCS documentation


neaweb6

Recommended Posts

Hey guys, I am replacing all of the support links in WHMCS to direct to my Kayako system. I changed the navigation links on the client area using a custom hook from the WHMCS documentation. This worked fine and here's the hook file:

 

<?php
// Call client area menu
use WHMCS\View\Menu\Item as MenuItem;

// Changes the Support > Tickets child menu text and URL
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $navItem = $primaryNavbar->getChild('Support');
   if (is_null($navItem)) {
       return;
   }

   $navItem = $navItem->getChild('Tickets');
   if (is_null($navItem)) {
       return;
   }

   $navItem->setLabel('My Conversations');
   $navItem->setUri('https://support.neawebservices.com/conversations');

});

// Changes the Open Ticket parent menu and url
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   $navItem = $primaryNavbar->getChild('Open Ticket');
   if (is_null($navItem)) {
       return;
   }

   $navItem->setLabel('Start a Conversation');
   $navItem->setUri('https://support.neawebservices.com/conversation/new');

});

// Removes the Knowledgebase child menu from the Support parent menu
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Support'))) {
       $primaryNavbar->getChild('Support')->removeChild('Knowledgebase');
   }
});
?>

 

I followed the documentation to change the Support sidebar that shows up using the same method, but I am getting a 500 error after submitting the changes. Here's the hook I am using:

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   $primarySidebar->getChild("Support")
       ->getChild("Support Ticket")
       ->setLabel("My Conversations");
});
?>

Link to comment
Share on other sites

you need to check if the requested item is not NULL first before performing any actions

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   if (!is_null($primarySidebar->getChild("Support"))){
       if (!is_null($primarySidebar->getChild("Support")->getChild("Support Ticket"))){
               $primarySidebar->getChild("Support")
               ->getChild("Support Ticket")
               ->setLabel("My Conversations");
       }
   }
});

Link to comment
Share on other sites

you need to check if the requested item is not NULL first before performing any actions

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   if (!is_null($primarySidebar->getChild("Support"))){
       if (!is_null($primarySidebar->getChild("Support")->getChild("Support Ticket"))){
               $primarySidebar->getChild("Support")
               ->getChild("Support Ticket")
               ->setLabel("My Conversations");
       }
   }
});

 

Thank you!!

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