Jump to content

Sidebar Hooks Problem


John

Recommended Posts

I am trying to remove the "Private Nameservers" sidebar menu item in domain management, but it don't seem to work. I try the following code and I get the dreaded OOPS message indicating a crash.

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
    $primarySidebar->getChild('Domain Details Management')
        ->removeChild('Manage Private Nameservers');
});

I ended up temporarily hiding it with CSS:

#Primary_Sidebar-Domain_Details_Management-Manage_Private_Nameservers {
    display: none;
}

But I would prefer to do this with a hook. Any help would be appreciated.

Link to comment
Share on other sites

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   if (!is_null($primarySidebar->getChild('Domain Details Management'))) {
            $primarySidebar->getChild('Domain Details Management')
                           ->removeChild('Manage Private Nameservers'); 
   }
});

where you were going wrong is that you first need to check that the sidebar/child you want to remove exists, and only if it exists, can you then remove or change it... your hook code will run on every client page, and on any page that shows the "Private Nameservers" child, it will work fine; but on any page where that child doesn't exist, you'll get the oops message... because you're telling WHMCS to remove something that doesn't exist.

Link to comment
Share on other sites

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