Jump to content

Hook needs to be activated when users are logged in


Tapeix

Recommended Posts

Ok guys, I have created a hook (based on WHMCS given examples) and finally created a new widget in WHMCS brand new sidebar, yay! :) However, this widgets needs to be activated when users are logged in; not when guests are visiting my WHMCS installation, so I added: App::getCurrentFilename() == 'clientarea'. Unfortunately, this is far from perfect, since the widget is also being displayed at the login page. Of course, I can remove with a little .css styling, but even when I do this, the widget isn't displayed on the network status page or the knowledgebase.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;
$client = Menu::context('client');
if(App::getCurrentFilename() == 'clientarea' && $_SESSION['Language']!="english")
add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar)
{
   $secondarySidebar->addChild('shortcuts', array(
       'label' => 'Useful shortcuts',
       'uri' => '#',
       'icon' => 'fa-question-circle',
   ));

 

Does anyone have a better option? Thanks!

Edited by Tapeix
Link to comment
Share on other sites

oh don't call them widgets, i'll get confused! :twisted: widgets are in the admin area, these are sidebars....

 

you almost had it - you need to check the value of $client to see if they're logged in or not... if they're not logged in (a guest), the variable won't exist... if they are, it will...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
   $client = Menu::context('client');
   if (!is_null($client)) {
               $secondarySidebar->addChild('shortcuts', array(
                   'label' => 'Useful shortcuts',
                   'uri' => '#',
                   'icon' => 'fa-question-circle'));
   }
});

with regards to language, because this hook only applies to clients, you could use $client->language to check - but if you're trying to make the sidebar multilingual, there are better methods.

Link to comment
Share on other sites

Thanks Brian! This is what my php code looks like now. :) Works like a charm.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
  $client = Menu::context('client') ;
  if (!is_null($client)  && $_SESSION['Language']!="english") {

   $secondarySidebar->addChild('shortcuts', array(
       'label' => 'Shortcuts',
       'uri' => '#',
       'icon' => 'fa-question-circle'));

   $ShortcutsPanel = $secondarySidebar->getChild('shortcuts');
   $ShortcutsPanel->moveToBack();

   $ShortcutsPanel->addChild('smssettings', array(
       'uri' => '#', 
       'label' => 'SMS settings', 
       'order' => 1,
       'icon' => 'fa-mobile'));
  }
});

Edited by Tapeix
Link to comment
Share on other sites

if you wanted to, you could trim that code a little...

 

 <?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
  $client = Menu::context('client') ;
  if (!is_null($client)  && $_SESSION['Language']!="english") {

   $secondarySidebar->addChild('shortcuts', array(
       'label' => 'Shortcuts',
       'uri' => '#',
       'icon' => 'fa-question-circle'))
                   ->moveToBack();
   $secondarySidebar->addChild('smssettings', array(
       'uri' => '#', 
       'label' => 'SMS settings', 
       'order' => 1,
       'icon' => 'fa-mobile'));
  }
});

it's probably also worth adding that I don't think $_SESSION['Language'] exists when you first visit the site, unless the language has been specified, either in the URL or by clicking a language link - only then will it available to be used in the way you want to.

Edited by brian!
Link to comment
Share on other sites

Okidoki! :)

 

I have no idea how to force language. Maybe if I add:

 

!is_null(['Language']!="english"))

 

...but I don't think this would work.

 

@Brian!, could you please help me with the link below? I'm looking for a solution to integrate Gravity Forms (Wordpress) with WHMCS for over a year. I try to export data from Gravity Forms to WHMCS (e.g. adding clients in WHMCS with the given information by Gravity Forms). With the release of WHMCSv6, I try to find someone again. >> http://forums.whmcs.com/showthread.php?108734-API-doesn-t-work

Link to comment
Share on other sites

Okidoki! :)

 

I have no idea how to force language. Maybe if I add:

 

!is_null(['Language']!="english"))

 

...but I don't think this would work.

the easiest way to force a language would be to add it to the URL... but you shouldn't really need to for this hook.

 

as you want this hook to only work for logged-in clients, you can get their default language from existing variables without the need for session variables... if they change their language while logged in, it changes their default language to that - so the variable should always exist.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
  $client = Menu::context('client');
  if (!is_null($client) && ($client->language !="english")) {

   $secondarySidebar->addChild('shortcuts', array(
       'label' => 'Shortcuts',
       'uri' => '#',
       'icon' => 'fa-question-circle'))
                   ->moveToBack();
   $secondarySidebar->addChild('smssettings', array(
       'uri' => '#', 
       'label' => 'SMS settings', 
       'order' => 1,
       'icon' => 'fa-mobile'));
  }
});

 

@Brian!, could you please help me with the link below? I'm looking for a solution to integrate Gravity Forms (Wordpress) with WHMCS for over a year. I try to export data from Gravity Forms to WHMCS (e.g. adding clients in WHMCS with the given information by Gravity Forms). With the release of WHMCSv6, I try to find someone again. >> http://forums.whmcs.com/showthread.php?108734-API-doesn-t-work

i'm not reading any API manuals on a Sunday afternoon! :)

posting in Marketplace and requesting quotes is probably a better option to find a solution for this.

Link to comment
Share on other sites

  • 5 weeks later...
Hmm, I need to hide this hook when a user is in /clientarea.php?action=productdetails. How can I do this? This is what it looks when I am navigating in my product details for example... not what it ment to be. :P

 

[ATTACH=CONFIG]9834[/ATTACH][ATTACH=CONFIG]9835[/ATTACH]

this issue could be fixed without hiding your sidebar

http://forum.whmcs.com/showthread.php?106891-Display-Credit-Balance-In-Six-Template&p=448314#post448314

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