Jump to content
Craft

Changing Theme SidebarNav with hook

Recommended Posts

I would like to remove some SidebarNav using this hook (https://developers.whmcs.com/themes/sidebars/)

I tried to remove "My Account" section in "Account Details" page with menuitemname "My Account" using the following code and it WORKS FINE :)

<?php
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
    if (!is_null($primarySidebar->getChild('My Account'))) {
        $primarySidebar->removeChild('My Account');
    }
});

My issue that I would like to remove the following sections from other pages but it doesn't work.

It doesn't work for "Contacts" section in "Home" page with menuitemname "Client Contacts"
It doesn't work for "Shortcuts" section in "Home" page with menuitemname "Client Shortcuts"
It doesn't work for "Actions" section in "Services" page with menuitemname "My Services Actions"
It doesn't work for "Actions" section in "My Domains" page with menuitemname "My Domains Actions"
It doesn't work for "Billing" section in "Billing" page with menuitemname "Billing"
It doesn't work for "Support" section in "Support Tickets" page with menuitemname "Support"
It doesn't work for "Actions" section in "View Cart" page with menuitemname "Actions"

Example:

if (!is_null($primarySidebar->getChild('My Services Actions'))) {
        $primarySidebar->removeChild('My Services Actions');
}

 

Share this post


Link to post
Share on other sites
8 hours ago, Craft said:

My issue that I would like to remove the following sections from other pages but it doesn't work.

because the sidebars you list will be secondary sidebars, not primary - so you're using the wrong hook for them. 🙂

certainly, standard_cart doesn't use primary sidebars, only secondary.

i'll give you a starting point for the first two sidebars you want to hide...

... but basically it's going to be one file with two hooks in it - the first taking care of the primary sidebars (as you're currently does); the second doing the same for the secondary sidebars (with my sample code as a starting point).

the code to remove these sidebars is exactly the same, you just need to choose the correct hook point for each sidebar.

you could use the ClientAreaSidebars hook and that would allow you to do this in one hook point, but there's no real advantage (other than brevity of code).

or if all you're going to do is hide these sidebars, and depending on the template, you might be able to do so with CSS in a custom.css file.

Share this post


Link to post
Share on other sites
1 hour ago, brian! said:

because the sidebars you list will be secondary sidebars, not primary - so you're using the wrong hook for them. 🙂

certainly, standard_cart doesn't use primary sidebars, only secondary.

i'll give you a starting point for the first two sidebars you want to hide...

... but basically it's going to be one file with two hooks in it - the first taking care of the primary sidebars (as you're currently does); the second doing the same for the secondary sidebars (with my sample code as a starting point).

the code to remove these sidebars is exactly the same, you just need to choose the correct hook point for each sidebar.

you could use the ClientAreaSidebars hook and that would allow you to do this in one hook point, but there's no real advantage (other than brevity of code).

or if all you're going to do is hide these sidebars, and depending on the template, you might be able to do so with CSS in a custom.css file.

Perfect I did it, thank you :)

Share this post


Link to post
Share on other sites
1 hour ago, brian! said:

because the sidebars you list will be secondary sidebars, not primary - so you're using the wrong hook for them. 🙂

 

Regarding to "Open Ticket" page, the secondary sidebar nav "Support" is only appearing when there a "Recent Tickets" available.

And if there is no any "Recent Tickets", the "Support" nav is disappeared.

How can I show "Support" nav all the time?

Support-Secondary-Sidebar-Nav.png

Open Ticket.png

Share this post


Link to post
Share on other sites
23 hours ago, Craft said:

How can I show "Support" nav all the time?

that sidebars conditionality will be determined in an encrypted file somewhere, so the solution often suggested is a secondary sidebar hook that recreates that entire sidebar.

Share this post


Link to post
Share on other sites
48 minutes ago, brian! said:

that sidebars conditionality will be determined in an encrypted file somewhere, so the solution often suggested is a secondary sidebar hook that recreates that entire sidebar.

Ok fine, I found this hook to add anything to (Open Ticket) page

add_hook('ClientAreaPageSubmitTicket', 1, function($vars)
{
    if (!is_null($secondarySidebar->addChild('Test'))) {
        $secondarySidebar->getChild('Test')
            ->addChild('Test');
    }
});

But it doesn't work, I think I need to edit something in the code :)

I tried also 

add_hook('ClientAreaPageSubmitTicket', 1, function(MenuItem $secondarySidebar)

But doesn't work too.

 

Reference: https://developers.whmcs.com/hooks-reference/ticket/

Edited by Craft

Share this post


Link to post
Share on other sites
21 hours ago, Craft said:

Ok fine, I found this hook to add anything to (Open Ticket) page - But it doesn't work, I think I need to edit something in the code 🙂

the solution (or at least the starting point) is already out there! 🙂

 

looking at David's code, one obvious bug is that the uri filenames (the links in each child) should ideally end in .php (otherwise it might generate a site error) - unless you're redirecting these links outside of WHMCS.

only the first three sidebar children have been created in the above hook, but hopefully you can see how simple it is to add new children for downloads, open ticket etc. 🙂

Share this post


Link to post
Share on other sites
On 12/3/2019 at 2:59 PM, brian! said:

the solution (or at least the starting point) is already out there! 🙂

 

looking at David's code, one obvious bug is that the uri filenames (the links in each child) should ideally end in .php (otherwise it might generate a site error) - unless you're redirecting these links outside of WHMCS.

only the first three sidebar children have been created in the above hook, but hopefully you can see how simple it is to add new children for downloads, open ticket etc. 🙂

That's what I need exactly, thank you :)

Share this post


Link to post
Share on other sites

Hi. I hope you're doing great today Guys! Just need some guidance for this "yours truly", as I'd like to remove this on my sidebar http://prntscr.com/qlu8ag

Or maybe at least modify them. That's from the MarketConnect Sitelock VPN which do not hide whenever I try to hide it in the products/services settings 

Share this post


Link to post
Share on other sites

if you go to the MarketConnect page in the setup menu, click on Sitelock -> manage -> Other Settings -> Landing Page Links... and switch it to off, that should remove it from the sidebar...

it could be removed with a hook if it has too, but switching it off via settings would be the easiest way.

Share this post


Link to post
Share on other sites
5 minutes ago, Mauwiks said:

I already did this but it's still showing up http://prntscr.com/qlulzs

take a look in the other settings tab and see if the landing pages option is enabled - if so, turn it off.

13 minutes ago, Mauwiks said:

I actually want to only edit the sidebar and add additional links with text like the other ones if possible but it seems it's not showing

if you wanted to add other links to that sidebar, it should require a hook like the one below....

<?php

use WHMCS\View\Menu\Item as MenuItem;
 
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) {
	if (!is_null($secondarySidebar->getChild('Categories'))) {
		$secondarySidebar->getChild('Categories')->addChild('Other Link 1')->setUri('https://www.google.com')->setOrder(1000);
	}
});

editing an existing child would just need getchild to the specific child and then set a new label/link etc - same with removing, just check the child exists and then remove it.

Share this post


Link to post
Share on other sites

I can't seem to remove 'VPN' http://prntscr.com/qlvjxe

with this code:
 

<?php

use WHMCS\View\Menu\Item as MenuItem;
 
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) {
    if (!is_null($secondarySidebar->getChild('Categories'))) {
        $secondarySidebar->removeChild('VPN');
    }
});

Share this post


Link to post
Share on other sites
6 minutes ago, Mauwiks said:

I can't seem to remove 'VPN'

it's a child, so you'll need to grab the parent first...

$secondarySidebar->getChild('Categories')->removeChild('VPN');

this should work assuming that another hook hasn't removed it, or you disable it in the settings.... and it's actually called VPN (it might be 'vpn').

Share this post


Link to post
Share on other sites

Yes, I already interchange them but still don't:

<?php

use WHMCS\View\Menu\Item as MenuItem;
 
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) {
    if (!is_null($secondarySidebar->getChild('Categories'))) {
                $secondarySidebar->getChild('Categories')->removeChild('vpn');
    }
});

Share this post


Link to post
Share on other sites
3 minutes ago, Mauwiks said:

Yes, I already interchange them but still don't:

if you look at the page source in the browser, what's the menuitemname value for VPN ? whatever that value is, that will be what you need to use in the hook.

Share this post


Link to post
Share on other sites

from that, it should be sitelockvpn - if that gets you nowhere, it has an ID value - so you could hide it using CSS as a last resort.

Share this post


Link to post
Share on other sites

Got the issue. It didn't work earlier because I renamed the file ""sidebars.php_disabled" lol. What the........... I wasted almost an hour of thinking about what's going on. Cheers. 😄 Thanks Bry! @brian! As usual.......

<?php

use WHMCS\View\Menu\Item as MenuItem;
 
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar) {
    if (!is_null($secondarySidebar->getChild('Categories'))) {
                $secondarySidebar->getChild('Categories')->removeChild('sitelockvpn');
    }
});

Share this post


Link to post
Share on other sites
Just now, Mauwiks said:

It didn't work earlier because I renamed the file ""sidebars.php_disabled" lol.

lol - i've been there. 🙄

Share this post


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