Jump to content

Removing Sidebar Menu Items, Hooks Not Working?


Recommended Posts

I want to remove the Knowledgebase and Downloads menu items from the client area. I used the webhook for the main nav as described here and it worked fine. However, trying to use these instructions for the sidebar is not working at all.

This is my code:

<?php

use WHMCS\View\Menu\Item as MenuItem;

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

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
    $primarySidebar->getChild('Support')
        ->removeChild('Knowledgebase');

	$primarySidebar->getChild('Support')
        ->removeChild('Downloads');
});

 

Link to comment
Share on other sites

This is what you need:

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
    $secondarySidebar->getChild('Support')
        ->removeChild('Knowledgebase')
        ->removeChild('Downloads');
        
});

 

Link to comment
Share on other sites

Thank you, but I've tried that and I get this when trying to access the site:

Oops!
Something went wrong and we couldn't process your request.
Please go back to the previous page and try again.

 

Link to comment
Share on other sites

I don't know. I have the file located here…

/includes/hooks/remove-items.php

And this is the entire code…

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
    $secondarySidebar->getChild('Support')
        ->removeChild('Knowledgebase')
        ->removeChild('Downloads');
        
});

 

But, this code works fine for the main nav…

<?php

use WHMCS\View\Menu\Item as MenuItem;

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

 

Link to comment
Share on other sites

1 hour ago, SimpleSonic said:

I've tested the hook prior to sharing the code, so there seems to be an issue with your implementation.

It's not.
On many pages, there's no support sidebar. Trying to access it will throw an exception.
This should work.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
    if(!is_null($secondarySidebar->getChild('Support')))
    {
        $secondarySidebar->getChild('Support')
        ->removeChild('Knowledgebase')
        ->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.

  • 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