Jump to content

ClientAreaPrimarySidebar Item in Home only


hostingarg

Recommended Posts

Hi.
I have a hook that generates a support pin for each client.
This support pin is displayed on ClientAreaPrimarySidebar.
I would like it to only be shown on the home page of the client area and not on all pages of the client area.
How could I do this?
The code (extracted from this same community) is the following:

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

  $client = Menu::context('client');
  if (!is_null($client)) {
$SupportPIN = generatePinCode($_SESSION['uid'], 8);
  $primarySidebar->addChild('Support-Pin', array(
        'label' => "Pin de Soporte",
        'uri' => '#',
        'order' => '10',
        'icon' => 'fa-ticket'
       
    ));
  //$primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
   }
});

add_hook('AdminAreaClientSummaryPage', 1, function($vars) {
    return 'Support Pin: ' . generatePinCode($vars['userid'], 8);
});

function generatePinCode($clientid = 0, $length = 6){
    $clientid = intval($clientid);
    preg_match_all('!\d+!', md5(date("y" . $clientid)), $matches);
    $numbers = join("", $matches[0]);
    return substr($numbers, 0, $length);
}

 

Thanks

Link to comment
Share on other sites

15 hours ago, hostingarg said:

The code (extracted from this same community) is the following:

original code from the thread below...

15 hours ago, hostingarg said:

I would like it to only be shown on the home page of the client area and not on all pages of the client area.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) {
	
	GLOBAL $smarty;
	$templatefile = $smarty->getVariable('templatefile');
	$client = Menu::context('client');
	if (!is_null($client) && in_array($templatefile, array('clientareahome'))) {
		$SupportPIN = generatePinCode($_SESSION['uid'], 8);
		$primarySidebar->addChild('Support-Pin', array(
			'label' => "Pin de Soporte",
			'uri' => '#',
			'order' => '10',
			'icon' => 'fa-ticket'
		));
		$primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
	}
});

the second hook in the file would remain the same as that refers to the admin area.

Link to comment
Share on other sites

1 hour ago, brian! said:

original code from the thread below...


<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar) {
	
	GLOBAL $smarty;
	$templatefile = $smarty->getVariable('templatefile');
	$client = Menu::context('client');
	if (!is_null($client) && in_array($templatefile, array('clientareahome'))) {
		$SupportPIN = generatePinCode($_SESSION['uid'], 8);
		$primarySidebar->addChild('Support-Pin', array(
			'label' => "Pin de Soporte",
			'uri' => '#',
			'order' => '10',
			'icon' => 'fa-ticket'
		));
		$primarySidebar->getChild('Support-Pin')->setBodyHtml($SupportPIN);
	}
});

the second hook in the file would remain the same as that refers to the admin area.

@brian! Thanks a lot! You are a master.

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