Jump to content

what im missing in this simple hook to hide a menu item?


plusplushosting

Recommended Posts

Hi there im trying to hide/remove the Networl status from the menu....but somehow im not getting it working.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
        if (!is_null($primaryNavbar->getChild('Network Status'))) {
                $primaryNavbar->getChild('Network Status')
                              ->removeChild('Network Status');
        }
});

 

Any idea where is my error?

Thanx in advance!

Link to comment
Share on other sites

ok, got it working.

Thanx!

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

});


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

});

 

Link to comment
Share on other sites

2 hours ago, plusplushosting said:

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

This is the result I suggested, and what's "fixed" the menu. "remove the middle one, and you were missing the first part of the last line..."
The top half of your hook (everything before the second "add_hook) isn't doing anything, I'd say.

Link to comment
Share on other sites

13 hours ago, plusplushosting said:

ok, got it working.

not that it particularly matters, but you don't need two separate hooks like that - just move the second IF statement to after the first IF Statement in the first hook and you're done.

2 minutes ago, bear said:

How odd. I based my theme on six, and it doesn't show the support options at all in the main menu if they're not logged in, and the code I gave hides the network bits when they are. 

@plusplushosting is right in what he says - now in theory the way he's doing might cause an error if there were another hook running that removed the Support/Network Status before this hook ran, but I guess it's highly unlikely that would occur (unless you had a lot of separate hooks and forget what they do & when they ran). 🙂

Link to comment
Share on other sites

2 hours ago, bear said:

How odd. I based my theme on six, and it doesn't show the support options at all in the main menu if they're not logged in, and the code I gave hides the network bits when they are. 

that's right - that support menu only shows for loggedin clients, but because they have a unique name, you don't need to check whether the client is logged in before removing it... ideally, you probably should do and apply other checks too, but in practice, and because it's a default menu, you don't usually *need* to.

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