Jump to content

Changing Theme SidebarNav with hook


Craft

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

 

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

Link to comment
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 :)

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

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

Link to comment
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 :)

Link to comment
Share on other sites

  • 1 month later...

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.

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

Link to comment
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').

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

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

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