Jump to content
  • 0

Adding menu entry with hooks in addon module


Dylank

Question

Hello,

 

I've built an addon module. I'm now trying to add a link to my module in the "services" menu in the client portal. In my /modules/addon/promodule/ folder I created a file called "hooks.php" in this file I have the following.

 

<?php 

if (!defined("WHMCS")) {
    die("This file cannot be accessed directly");
}

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
 
       $primaryNavbar->getChild('Services')
           ->addChild('pro-module', array(
        'label' => 'Pro Module',
        'uri' => 'index.php?m=promodule',
        'order' => 20,
    ));
});



However it does not load the menu entry.  If I place the file in /includes/hooks/ it however loads the menu entry. Is this intended behavior and I'm required to have a separate file outside my addon module to add the menu entry ? 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
On 7/6/2021 at 5:16 AM, Dylank said:

Hello,

 

I've built an addon module. I'm now trying to add a link to my module in the "services" menu in the client portal. In my /modules/addon/promodule/ folder I created a file called "hooks.php" in this file I have the following.

 


<?php 

if (!defined("WHMCS")) {
    die("This file cannot be accessed directly");
}

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
 
       $primaryNavbar->getChild('Services')
           ->addChild('pro-module', array(
        'label' => 'Pro Module',
        'uri' => 'index.php?m=promodule',
        'order' => 20,
    ));
});



However it does not load the menu entry.  If I place the file in /includes/hooks/ it however loads the menu entry. Is this intended behavior and I'm required to have a separate file outside my addon module to add the menu entry ? 

hi @Dylank

Please sure your hooks.php is on the active module folder
if the module is active, whmcs will load the hooks.php file

Link to comment
Share on other sites

  • 0

You probably added the hooks.php file after the module was activated. If you add the file after the module activation, WHMCS will not load it automatically. To solve the problem, go to the addon settings and click on "Save Changes" for the relevant module without changing any settings. The hooks.php file will then be recognized by WHMCS.

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
Answer this question...

×   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