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

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 and understand your posts will initially be pre-moderated