Jump to content

Add item to secondary sidebar through hook


rvr

Recommended Posts

Hi!

I've tried this a dozen of times the last week, to no avail.

I am following the WHMCS docs step by step, doesn't seem to work when trying to add anitem to the secondary sidebar.

Strange thing is 😀 I can remove items.

This works for removing items:

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
    $client = Menu::context('client');
    if (!is_null($client)) {
        if (!is_null($secondarySidebar->getChild('Support'))) {
                $secondarySidebar->getChild('Support')
                                ->removeChild('Announcements')
                                ->removeChild('Knowledgebase')
                                ->removeChild('Network Status');
       }
   }
});

But when I add this:

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

{
    if (!is_null($secondarySidebar->getChild('Support'))) {
        $secondarySidebar->getChild('Support')
            ->addChild('Mailing List Subscription Prefs')
                ->setLabel('Subscription Preferences')
                ->setUri('subscriptionprefs.php')
                ->setOrder(100);
    }
});

This doesn't add any item.

(There are no PHP error messages.)

After trying a few days I still didn't get it to work.

Any info on why this is happening is more than welcome!

Thanks!

Best regards,

Robert

Link to comment
Share on other sites

Hi Robert,

On 16/10/2018 at 11:14, rvr said:

I've tried this a dozen of times the last week, to no avail.

I am following the WHMCS docs step by step, doesn't seem to work when trying to add anitem to the secondary sidebar.

that assumes the docs are completely accurate on this! 😛

On 16/10/2018 at 11:14, rvr said:

After trying a few days I still didn't get it to work.

Any info on why this is happening is more than welcome!

I can't see anything obviously wrong with the code - the PHP/use are missing, but I assume that's just for copy/paste convenience....

<?php
 
use WHMCS\View\Menu\Item as MenuItem;

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

{
	if (!is_null($secondarySidebar->getChild('Support'))) {
		$secondarySidebar->getChild('Support')
			->addChild('Mailing List Subscription Prefs')
			->setLabel('Subscription Preferences')
			->setIcon('fas fa-clipboard-list fa-fw') 
			->setUri('subscriptionprefs.php')
			->setOrder(100);
	}
});

for visible symmetry, i've added an icon to the child, but the above hook code works for me (it's virtually the same as yours)...

SGMT3Ov.png

 

Link to comment
Share on other sites

Hi Brian,

Because I've tried so many things, I think I got confused at some point 😁

I did remove items from the support section in the secondary sidebar.

But.... was it on the same page that I was trying to add to the the support section in the secondary sidebar.

Maybe support was non existing on the page were I was trying to add to it.

Thanks for thinking with me.

Now I was sure I was doing it the right way.

And.... I've found the solution to what I wanted.

Simply adding my item to the Actions-menu did the trick.

Thanks!

Best regards,

Robert

Link to comment
Share on other sites

  • 1 year later...

Hello, i am trying to develop whmcs but getting active class issue. It's act as active always. 

<?php
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimarySidebar', 1, function($primarySidebar) {
  $newMenu->addChild(
        'contacts',
        array(
            'name' => 'My Contacts',
            'label' => Lang::trans('managecontacts'),
            'uri' => 'mcontacts/',
            'order' => 4,
        )
    )->setClass(( ! isset($_GET['modop']) ? 'active' : ''));
}

Does below code still working or some changes are made on new version?

->setClass(( ! isset($_GET['modop']) ? 'active' : ''))

 

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