Jump to content
plusplushosting

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

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!

Share this post


Link to post
Share on other sites
42 minutes ago, plusplushosting said:

$primaryNavbar->getChild('Network Status')

This middle line isn't needed, and the line after is missing the beginning:

$primaryNavbar->removeChild('Network Status');

  • Like 1

Share this post


Link to post
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');
        }

});

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Thanx !

The first half is removing the item from the menu when the client is logged in, at least in my theme. I guess the second half work ok in the default six theme even when they are logged in.

Thanx again Bear!

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
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). 🙂

Share this post


Link to post
Share on other sites

Never mind. As long as it works for him. 

Edited by bear

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines