Jump to content

Hook not firing


MarkVDD

Recommended Posts

Hey all!

Just a sidenote, I just started getting into WHMCS and know little to nothing about it, just following the docs and seeing what I can do.

 

I am trying to remove the divider in the default navbar when you click on "Account" in between Login and Forgot Password?

 

The code I am using is located in the /includes/hooks folder (named removeDivider.php if it is of any use) and is as follows:
 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondaryNavbar', 1, function (MenuItem $secondaryNavbar) {
    if (!is_null($secondaryNavbar->getChild('Account'))) {
        $secondaryNavbar->getChild('Account')->removeChild('Divider');
    }
});

 

Now when I look at the frontend again I see no change, I tried 

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {

too, but without success, and I am starting to wonder if the hook is firing at all? Am I maybe using the wrong hook? Any help is greatly appreciated 🙂

Link to comment
Share on other sites

17 hours ago, Hosternate said:

Just a sidenote, I just started getting into WHMCS and know little to nothing about it, just following the docs and seeing what I can do.

that assumes that the example hooks posted in the docs actually work under all conditions... some don't and never have. headshake.gif

there will be better examples of working navbar hooks posted in these forums over the last few years.

17 hours ago, Hosternate said:

The code I am using is located in the /includes/hooks folder (named removeDivider.php if it is of any use) and is as follows:

your first hook as written works for me....

YmuNrmF.png

as a sidenote, if the user was logged in, your hook would also remove the divider above Logout (red arrow) - you may or may not want that.... if you wanted to keep that logged in divider, the hook would need to determine if the client was logged in or not before removing the divider child.

iUqOqhw.png

17 hours ago, Hosternate said:

I tried 


add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {

too, but without success, and I am starting to wonder if the hook is firing at all?

well that definitely wouldn't work as the primary navbar is the one on the left hand side; secondary is on the right.

sometimes depending on the browser, you have to use shift+refresh (or equivalent) to see visible hook changes.... or you may need to clear the template cache.... or you might be using Cloudflare or similar and your still seeing the old cached version.

 

Link to comment
Share on other sites

6 hours ago, brian! said:

that assumes that the example hooks posted in the docs actually work under all conditions... some don't and never have. headshake.gif

there will be better examples of working navbar hooks posted in these forums over the last few years.

your first hook as written works for me....

YmuNrmF.png

as a sidenote, if the user was logged in, your hook would also remove the divider above Logout (red arrow) - you may or may not want that.... if you wanted to keep that logged in divider, the hook would need to determine if the client was logged in or not before removing the divider child.

iUqOqhw.png

well that definitely wouldn't work as the primary navbar is the one on the left hand side; secondary is on the right.

sometimes depending on the browser, you have to use shift+refresh (or equivalent) to see visible hook changes.... or you may need to clear the template cache.... or you might be using Cloudflare or similar and your still seeing the old cached version.

 

Ah, I see what I have done wrong. I made the folder in my child theme, so child_theme/includes/hooks/ But it needs to be in the root/includes/hooks. Thanks for making me double check 😛

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