Difference between revisions of "Working With Client Area Home Page Panels"

From WHMCS Documentation

(Created page with "Like the client area's navigation and sidebars, the panels displayed on the client area home page are based on a tree structure of menu item objects. These panels are displaye...")
 
(Interacting With Homepage Panels)
 
(15 intermediate revisions by 7 users not shown)
Line 1: Line 1:
Like the client area's navigation and sidebars, the panels displayed on the client area home page are based on a tree structure of menu item objects. These panels are displayed on the home page to present quick information to a client after they log in, such as overdue invoices, links to active products and services, and domains that are soon to expire. Like the client area's navigation and sidebars, these panels can be modified programmatically. Working with these panels is nearly identical to modifying navbars and side bars.  
+
Like the Client Area's navigation and sidebars, the panels displayed on the Client Area homepage are based on a tree structure of menu item objects. These panels display on the homepage to present quick information like overdue invoices or links to active services to a client after they log in. Modifying these panels is very similar to modifying navbars and side bars.
 
+
=Panel Structure=
+
== Panel Structure ==
 
+
The client area's panels have an invisible root item. Each panel is a child of that invisible root item. Many panels in turn have their own child items that are rendered as lists of links inside the panel.  
+
The Client Area's panels have an invisible root item. Each panel is a child of that invisible root item. Many of these panels render their own child items as lists of links inside the panel.
 
+
 
* ''root item''
 
* ''root item''
 
** panel item
 
** panel item
Line 14: Line 14:
 
*** line item
 
*** line item
 
** panel item
 
** panel item
 
+
=Panel Layout=
+
== Panel Layout ==
 
+
==Desktop Mode==
+
=== Desktop Mode ===
 
+
[[Image:Desktop mode client panels.png|thumb|The WHMCS 6.0 client area homepage panel layout in desktop mode]] When viewed in desktop mode, typically on desktop web browsers, client are homepage panels are rendered in two columns. Odd numbered panels are rendered on the left column and even numbered panels are rendered on the right column.
+
[[Image:85DesktopClientPanels.png|thumb|The WHMCS 8.5 Client Area homepage panel layout in desktop mode]] When viewed in desktop mode, typically on desktop web browsers, most client area homepage panels render in two columns. In [[Version 8.5 Release Notes|WHMCS 8.5 and later]], it is also possible to create panels that span both columns.
 
+
 +
* For single-column panels, odd numbered panels are rendered on the left column and even numbered panels are rendered on the right column.
 +
* Panels that span both columns will render above the two-column layout, separately from the array of panels. Because of this, if a two-column panel is present, a single-column even numbered panel can become an odd-numbered panel.
 +
 +
=== Responsive Mode ===
 +
 +
[[Image:85ResponsiveClientPanels.png|thumb|The WHMCS 8.5 Client Area homepage panel layout in responsive mode]] Responsive mode activates when the Client Area displays on a smaller screen, typically a phone or tablet. Responsive mode renders all panels in a single column with the left column over the right column. Odd-numbered panels display above even-numbered panels in responsive mode.
 +
 
<div style="clear: both"></div>
 
<div style="clear: both"></div>
 
+
==Responsive Mode==
+
== Differences With Navigation And Sidebar Menu Items ==
 
+
[[Image:Responsive mode client panels.png|thumb|The WHMCS 6.0 client area homepage panel layout in responsive mode]] Responsive mode is activated when the client ares is viewed on a smaller screen, typically on a phone or tablet. Responsive mode renders all panels in a single column, with the left column placed over the right column. This means that odd numbered panels are displayed above even numbered panels in responsive mode.
+
When it renders, a Client Area homepage panel resembles a panel in the sidebar. It uses the same underlying structure as the menu item objects that render the sidebar with a few changes:
 
+
<div style="clear: both"></div>
+
=== Linking ===
 
+
=Differences With Navigation And Sidebar Menu Items=
+
A homepage panel's label is not a clickable link. Setting a URI on a homepage panel has no effect in WHMCS.
 
+
[[Image:Client area panel item.png|thumb|A client area home page panel represented as menu item properties]] When rendered, a client area home page panel resembles a panel in the sidebar. It uses the same underlying structure as the menu item objects that render the sidebar, though with a number of changes:
+
=== Custom Colors ===
 
+
A home page panel's label is not a clickable link. Setting a URI on a home page panel has no effect in WHMCS.
+
Panels can render in a custom color when you define the <tt>color</tt> menu item attribute.
 
+
Panels can be rendered in a custom color to give it a unique effect. Define the '''color''' menu item attribute to set this color. The following colors are available:
+
The following colors are available:
 
+
 
* gold
 
* gold
 
* green
 
* green
Line 56: Line 63:
 
* silver
 
* silver
 
* asbestos
 
* asbestos
 
+
Finally, a home page panel has an optional button rendered to the right of the panel's label and badge. Define the following menu item extras to render a button in a home page panel:
+
=== Optional Button ===
 
+
* '''btn-link''': The URL to load in the user's web browser when the button is clicked.
+
Each homepage panel has an optional button that renders to the right of the panel's label and badge.
* '''btn-text''': The text within the button.
+
* '''btn-icon''': An optional Font Awesome icon to display to the left of the button's text.
+
Define the following menu item extras to render a button in a homepage panel:
 
+
 +
* '''btn-link''' The URL to load in the user's web browser when the viewer clicks the button.
 +
* '''btn-text''' The text within the button.
 +
* '''btn-icon''' An optional Font Awesome icon to display to the left of the button's text.
 +
* '''colspan''' — In WHMCS 8.5 and later, an optional Boolean value that causes the panel to span both columns.
 +
 
<div style="clear: both"></div>
 
<div style="clear: both"></div>
 
+
=Default Panels=
+
== Default Panels ==
 
+
The following panels are defined by default. Please note that hooks can register additional panels as well as interact with the default ones, so there is no guarantee that these panels will be visible, or necessarily in the given display orders.
+
The following panels are defined by default. Hooks can register additional panels as well as interact with the default ones, so there is no guarantee that these panels will be visible or use this display order.
 
+
In addition, most of the panels are conditional. They only display when certain conditions are met in addition to the user having the appropriate permissions.
+
In addition, most of the panels are conditional and require the user to have the appropriate permissions.
 
+
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 91: Line 103:
 
| 50
 
| 50
 
| Manage Domains
 
| Manage Domains
| At least one domain expiring within 30 days
+
| At least one domain expiring within 45 days
 
|-
 
|-
 
| Active Products/Services
 
| Active Products/Services
 
| 100
 
| 100
| Manage Products  
+
| Manage Products
 
| ''None''
 
| ''None''
 
|-
 
|-
Line 112: Line 124:
 
| ''None''
 
| ''None''
 
| At least one file associated with the client's account
 
| At least one file associated with the client's account
|-  
+
|-
 
| Affiliate Program
 
| Affiliate Program
 
| 300
 
| 300
Line 124: Line 136:
 
|-
 
|-
 
|}
 
|}
 +
 +
== Interacting With Homepage Panels ==
 +
 
 +
You can use WHMCS’ <tt>add_hook()</tt> function to call custom code when WHMCS is rendering homepage panels.
 +
 
 +
* The <tt>ClientAreaHomepagePanels</tt> hook allows you to manipulate the Client Area homepage's panels.
 +
** Call this hook before you assign the panel object to the view template.
 +
** This hook passes the Client Area home panel's root item to the hook function.
 +
* For more information about using the hook system and supported hook functions, see [https://developers.whmcs.com/hooks/ our Developer Documentation].
 +
 
 +
In WHMCS 8.5 and later, you can use the <tt>CustomActions</tt> server module function to define items that perform a set function and then redirect the user to a specified URL.
 +
 
 +
* Customers can invoke items from within the Client Area.
 +
* Use this to specfically add items to the '''My Active Products/Services''' panel in the Client Area home page.
 +
* For more information on using custom actions, see [https://developers.whmcs.com/provisioning-modules/custom-actions/ our Developer Documentation].
 +
* You can also use this to add custom actions to [[Editing Client Area Menus|Client Area service sidebar menus]].
  
=Interacting With Home Page Panels=
+
== Examples ==
 
+
WHMCS 6.0 introduce a hook to allow manipulation of the client area home page's panels. Use WHMCS’ <tt>add_hook()</tt> function to call custom code when WHMCS is ready to render these panels.
+
=== Add a panel to the homepage ===
 
+
* '''ClientAreaHomepagePanels'''
+
[[Image:85-6-LocalTempsHomePanel.png|thumb|The WHMCS 6 client area homepage with a custom local temperatures panel highlighted.]]
** Called prior to assigning the panel object to the view template.
+
** Passes the client area home panels' root item to the hook function.
+
:''This example makes use of a free third-party service that is not part of WHMCS. WHMCS cannot guarantee the state of this service and uses it for example purposes only.''
 
+
=Examples=
+
This example uses the '''ClientAreaHomepagePanels''' hook and the menu item's <tt>addChild()</tt> and <tt>moveToFront()</tt> methods. The <tt>WHMCS\User\Client</tt> class contains the information to query for this example's weather data. This calls the United States National Weather Service's [http://graphical.weather.gov/xml/ National Digital Forecast Database web service] and requires [http://php.net/manual/en/book.soap.php SOAP] support in your PHP installation. It also uses the [https://github.com/briannesbitt/Carbon Carbon] library for date manipulation and display. The Carbon library is bundled with WHMCS 6.0 and later.
 
+
==Add a local temperature panel to the homepage==
+
To add this panel to the client area homepage:
 
+
[[Image:Local temperatures home page panel.png|thumb|The WHMCS 6 client area home page with a custom local temperatures panel highlighted.]]  
+
# Translate the logged in user's ZIP code into a latitude-longitude pair.
 
+
# Send the user's latitude-longitude pair to the NDFD service to retrieve their local forecast.
:''Please note that this example makes use of a free third party service unrelated to WHMCS. WHMCS cannot guarantee the state of this service and uses it for example purposes only.''
+
# Add a ''Local Temperatures'' child panel to the homepage panels list with today's temperatures in the panel's body HTML.
 
 
The powers that be at your hosting company have decided that they want to be their clients' single stop for everything and want to start providing a seamless general portal experience in addition to quality hosting. They feel that showing a simple temperature forecast after the user logs in is a good start to achieving it. Luckily, WHMCS provides a way to easily add this to the interface.
 
 
 
This example uses the '''ClientAreaHomepagePanels''' hook and the menu item's <tt>addChild()</tt> and <tt>moveToFront()</tt> methods. The <tt>WHMCS\User\Client</tt> class contains the information to query for weather data. This calls the United States National Weather Service's [http://graphical.weather.gov/xml/ National Digital Forecast Database web service] and requires [http://php.net/manual/en/book.soap.php SOAP] support in your PHP installation. It also uses the [https://github.com/briannesbitt/Carbon Carbon] library for date manipulation and display. The Carbon library is bundled with WHMCS version 6. To add this panel to the client area home page we must:
 
 
 
# Translate the logged in user's zip code into a latitude/longitude pair.
 
# Send the user's latitude/longitude pair to the NDFD service to retrieve their local forecast.
 
# Add a child panel to the home page panels list that has the label "Local Temperatures" and has today's temperatures in the panel's body HTML.
 
 
# Add child items to the panel for the next five days of temperatures. WHMCS will display these temperatures in a list inside the panel.
 
# Add child items to the panel for the next five days of temperatures. WHMCS will display these temperatures in a list inside the panel.
# Move the local temperatures to the beginning so it's displayed first.
+
# Move the local temperatures to the beginning so that they display first.
 
+
Create the <tt>includes/hooks/clientWeatherPanel.php</tt> file in your WHMCS installation and enter the code below. WHMCS will parse the file and hook on page load and will run the hook function when the client visits the home page after logging in.
+
Create the <tt>includes/hooks/clientWeatherPanel.php</tt> file in your WHMCS installation and enter the code below. WHMCS will parse the file and hook when the page loads. It will run the hook function when the client visits the homepage after logging in.
 
+
 
<div style="clear: both"></div>
 
<div style="clear: both"></div>
 
+
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
 
<?php
 
<?php
 
+
 
use Carbon\Carbon;
 
use Carbon\Carbon;
use WHMCS\User\Client;
+
use WHMCS\Authentication\CurrentUser;
 
use WHMCS\View\Menu\Item;
 
use WHMCS\View\Menu\Item;
 
+
 
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
 
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
 
{
 
{
 
     /** @var \WHMCS\User\Client $currentUser */
 
     /** @var \WHMCS\User\Client $currentUser */
     $currentUser = Client::find($_SESSION['uid']);
+
     $currentUser = CurrentUser::client();
 
     $today = Carbon::now()->startOfDay();
 
     $today = Carbon::now()->startOfDay();
 
+
 
     // Connect to the United States' National Weather Service.
 
     // Connect to the United States' National Weather Service.
 
     // See http://graphical.weather.gov/xml/ for more information.
 
     // See http://graphical.weather.gov/xml/ for more information.
 
     $soapClient = new SoapClient('http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl');
 
     $soapClient = new SoapClient('http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl');
 
+
 
     // The weather API takes a latitude/longitude pair as input. Translate the
 
     // The weather API takes a latitude/longitude pair as input. Translate the
 
     // current user's zip code into a coordinate pair.
 
     // current user's zip code into a coordinate pair.
 
     $response = simplexml_load_string($soapClient->LatLonListZipCode($currentUser->postcode));
 
     $response = simplexml_load_string($soapClient->LatLonListZipCode($currentUser->postcode));
 
     list ($latitude, $longitude) = explode(',', $response->latLonList);
 
     list ($latitude, $longitude) = explode(',', $response->latLonList);
 
+
 
     // Query for the weather forecast and turn it into display data.
 
     // Query for the weather forecast and turn it into display data.
 
     $response = simplexml_load_string($soapClient->NDFDGen($latitude, $longitude, 'glance'));
 
     $response = simplexml_load_string($soapClient->NDFDGen($latitude, $longitude, 'glance'));
 
     $maximumTemperatures = (array)$response->data->parameters->temperature[0]->value;
 
     $maximumTemperatures = (array)$response->data->parameters->temperature[0]->value;
 
     $minimumTemperatures = (array)$response->data->parameters->temperature[1]->value;
 
     $minimumTemperatures = (array)$response->data->parameters->temperature[1]->value;
 
+
 
     // Build the new temperature panel by adding a child panel to the panel
 
     // Build the new temperature panel by adding a child panel to the panel
 
     // list.
 
     // list.
 
     $todaysMaximum = $maximumTemperatures[0];
 
     $todaysMaximum = $maximumTemperatures[0];
 
     $todaysMinimum = $minimumTemperatures[0];
 
     $todaysMinimum = $minimumTemperatures[0];
 
+
 
     $weatherPanel = $homePagePanels->addChild('local temperatures', array(
 
     $weatherPanel = $homePagePanels->addChild('local temperatures', array(
 
         'label' => 'Local Temperatures',
 
         'label' => 'Local Temperatures',
Line 193: Line 213:
 
             'color' => 'blue',
 
             'color' => 'blue',
 
         ),
 
         ),
         'bodyHtml' => "<p>Today's temperature in {$currentUser->city}: {$todaysMinimum}&deg;F / {$todaysMaximum}&deg;F</p>",
+
         'bodyHtml' => "<p>Today's temperature in {$currentUser->city}: {$todaysMinimum}°F / {$todaysMaximum}°F</p>",
 
     ));
 
     ));
 
+
 
     // Add the 5-day temperature forecast as child items to the panel so WHMCS
 
     // Add the 5-day temperature forecast as child items to the panel so WHMCS
 
     // can present them nicely in a list.
 
     // can present them nicely in a list.
Line 202: Line 222:
 
         $minimumTemperature = $minimumTemperatures[$i];
 
         $minimumTemperature = $minimumTemperatures[$i];
 
         $maximumTemperature = $maximumTemperatures[$i];
 
         $maximumTemperature = $maximumTemperatures[$i];
 
+
 
         $weatherPanel->addChild($day->format('l, F j'), array(
 
         $weatherPanel->addChild($day->format('l, F j'), array(
 
             'label' => $day->format('l, F j'),
 
             'label' => $day->format('l, F j'),
 
             'icon' => 'fa-angle-double-right',
 
             'icon' => 'fa-angle-double-right',
             'badge' => "{$minimumTemperature}&deg;F / {$maximumTemperature}&deg;F",
+
             'badge' => "{$minimumTemperature}°F / {$maximumTemperature}°F",
 
             'order' => $i,
 
             'order' => $i,
 
         ));
 
         ));
 
     }
 
     }
 
+
 
     // Finally, move the panel to the beginning of the panel list so it's
 
     // Finally, move the panel to the beginning of the panel list so it's
 
     // displayed first.
 
     // displayed first.
Line 216: Line 236:
 
});
 
});
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
==Add a promotional offer panel==
+
=== Add a promotional offer panel ===
 
+
[[Image:Redeem offer home page panel.png|thumb|The WHMCS 6 client area home page in responsive mode with custom special offer panel highlighted.]] After a lengthy beta period, your company has just released the latest version of its flagship product. The users love it, and the orders are rolling in. The public beta period was so successful that management wants to offer a free month of the service to all existing clients. The promo page is ready to go, but all that's left is to inform the users. Thankfully WHMCS provides an easy way to let the users know about the special offer right after they log in.
+
[[Image:86RedeemOfferHomePanel.png|thumb|The WHMCS 6 client area homepage in responsive mode with custom special offer panel highlighted.]] Like the previous example, this example uses the '''ClientAreaHomepagePanels''' hook and the menu item's <tt>addChild()</tt> method. Unlike the previous example, it doesn't list child items but will use a panel's body HTML and custom button in the corner.
 
+
Like the previous example, this example uses the '''ClientAreaHomepagePanels''' hook and the menu item's <tt>addChild()</tt> and <tt>moveToFront()</tt> methods. Unlike the previous examples though it doesn't need a list of child items, but it will use a panel's body HTML and custom button in the corner. To add this panel to the client area home page we must:
+
To add this panel to the client area homepage:
 
+
# Add a child panel to the home page panels list that has the the following extras:
+
# Add a child panel to the homepage panels list that has the the following extras:
 
#* A '''btn-link''' extra containing a link to the special promo.
 
#* A '''btn-link''' extra containing a link to the special promo.
 
#* A '''btn-text''' extra containing the text of the button.
 
#* A '''btn-text''' extra containing the text of the button.
 
# Define body and footer HTML in the panel to make the promotion conform to WHMCS' look and feel.
 
# Define body and footer HTML in the panel to make the promotion conform to WHMCS' look and feel.
# Move the panel to the front so it's displayed first.
+
# Set the order to 20 to place it after the default unpaid and overdue invoice panels.
 
+
Create the <tt>includes/hooks/specialOfferPanel.php</tt> file in your WHMCS installation and enter the code below. As with the precious example, WHMCS will parse the file and hook on page load and will run the hook function when the client visits the home page after logging in.
+
Create the <tt>includes/hooks/specialOfferPanel.php</tt> file in your WHMCS installation and enter the code below. As with the previous example, WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.
 
+
 
<div style="clear: both"></div>
 
<div style="clear: both"></div>
 
+
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
 
<?php
 
<?php
 
+
 
use WHMCS\View\Menu\Item;
 
use WHMCS\View\Menu\Item;
 
+
 
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
 
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
 
{
 
{
Line 244: Line 264:
 
like to provide next month of service <strong>on the house</strong>.</p>
 
like to provide next month of service <strong>on the house</strong>.</p>
 
EOT;
 
EOT;
 
+
 
     // Add a homepage panel with a link to a free month promo and mode it to the
 
     // Add a homepage panel with a link to a free month promo and mode it to the
 
     // front of the panel list.
 
     // front of the panel list.
Line 250: Line 270:
 
         'label' => 'Thanks for the help!',
 
         'label' => 'Thanks for the help!',
 
         'icon' => 'fa-thumbs-up',
 
         'icon' => 'fa-thumbs-up',
 +
        'order' => 20,
 
         'extras' => array(
 
         'extras' => array(
 
             'color' => 'gold',
 
             'color' => 'gold',
Line 258: Line 279:
 
         'bodyHtml' => $thankYouMessage,
 
         'bodyHtml' => $thankYouMessage,
 
         'footerHtml' => 'Act fast! This offer expires soon!',
 
         'footerHtml' => 'Act fast! This offer expires soon!',
     ))
+
     ));
     ->moveToFront();
+
});
 +
</syntaxhighlight>
 +
 +
=== Modifying an existing panel ===
 +
 +
Another common item is to want to change a link button and its text in a home panel panel (for example: if you want to link to a third party ticket system you already have in place.
 +
 +
Create the <tt>includes/hooks/recentTicketsPanel.php</tt> file in your WHMCS installation and enter the code below. As with the previous example, WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.
 +
 +
<div style="clear: both"></div>
 +
 +
<syntaxhighlight lang="php">
 +
<?php
 +
 
 +
// This hook will adjust the button in the homepage panels. You have two
 +
// different options of setExtra() or setExtras(). Use of setExtras() requires
 +
// passing all 'extra' related vars through the array.
 +
 
 +
use WHMCS\View\Menu\Item;
 +
 
 +
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) {
 +
    $recentTicketsPanel = $homePagePanels->getChild('Recent Support Tickets');
 +
     
 +
    if (!is_null($recentTicketsPanel)) {
 +
        $recentTicketsPanel->setExtras(
 +
            [
 +
                'color' => 'amethyst',
 +
                'btn-text' => 'New Name Here',
 +
                'btn-link' => 'http://newlinkgoes.here',
 +
                'btn-icon' => 'fa-thumbs-o-down',
 +
            ]
 +
        );
 +
    }
 +
});
 +
</syntaxhighlight>
 +
 +
=== Rearranging an existing panel ===
 +
 +
You may wish to change the order in which a panel appears within the Client Area.
 +
 +
Create the <tt>includes/hooks/rearrangeRegisterDomainPanel.php</tt> file in your WHMCS installation and enter the code below. As with previous examples, WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.
 +
<div style="clear: both"></div>
 +
<syntaxhighlight lang="php">
 +
<?php
 +
 
 +
// This hook will rearrange the Register a New Domain panel
 +
// to be the first panel displayed in the client area
 +
 +
use WHMCS\View\Menu\Item;
 +
   
 +
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) {
 +
    if (!is_null($homePagePanels->getChild('Register a New Domain'))) {
 +
        $homePagePanels->getChild('Register a New Domain')
 +
        ->setOrder(0);
 +
     }
 +
});
 +
</syntaxhighlight>
 +
 +
=== Removing an existing panel ===
 +
 +
You may wish to remove a panel from the client area.
 +
 +
Create the <tt>includes/hooks/removeRegisterDomainPanel.php</tt> file in your WHMCS installation and enter the code below. As with previous examples, WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.
 +
<div style="clear: both"></div>
 +
<syntaxhighlight lang="php">
 +
<?php
 +
 
 +
// This hook will remove the Register a New Domain panel from the client area
 +
 +
use WHMCS\View\Menu\Item;
 +
   
 +
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) {
 +
    if (!is_null($homePagePanels->getChild('Register a New Domain'))) {
 +
        $homePagePanels->removeChild('Register a New Domain');
 +
    }
 +
});
 +
</syntaxhighlight>
 +
 +
=== Creating a two-column panel ===
 +
 +
You may wish to create a two-column panel above the one-column panel layout, or convert an existing panel.
 +
 +
To do this, create the <tt>includes/hooks/fullWidthRegisterDomainPanel.php</tt> file in your WHMCS installation and enter the code below. WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.
 +
 +
<syntaxhighlight lang="php">
 +
<?php
 +
 +
// This hook causes the Register a New Domain panel to be a two-column panel.
 +
 +
use WHMCS\View\Menu\Item;
 +
 +
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) {
 +
if (!is_null($homePagePanels->getChild('Register a New Domain'))) {
 +
$homePagePanels->getChild('Register a New Domain')->setExtra('colspan', true);
 +
}
 
});
 
});
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 18:44, 23 June 2022

Like the Client Area's navigation and sidebars, the panels displayed on the Client Area homepage are based on a tree structure of menu item objects. These panels display on the homepage to present quick information like overdue invoices or links to active services to a client after they log in. Modifying these panels is very similar to modifying navbars and side bars.

Panel Structure

The Client Area's panels have an invisible root item. Each panel is a child of that invisible root item. Many of these panels render their own child items as lists of links inside the panel.

  • root item
    • panel item
      • line item
      • line item
      • line item
    • panel item
      • line item
      • line item
    • panel item

Panel Layout

Desktop Mode

The WHMCS 8.5 Client Area homepage panel layout in desktop mode
When viewed in desktop mode, typically on desktop web browsers, most client area homepage panels render in two columns. In WHMCS 8.5 and later, it is also possible to create panels that span both columns.
  • For single-column panels, odd numbered panels are rendered on the left column and even numbered panels are rendered on the right column.
  • Panels that span both columns will render above the two-column layout, separately from the array of panels. Because of this, if a two-column panel is present, a single-column even numbered panel can become an odd-numbered panel.

Responsive Mode

The WHMCS 8.5 Client Area homepage panel layout in responsive mode
Responsive mode activates when the Client Area displays on a smaller screen, typically a phone or tablet. Responsive mode renders all panels in a single column with the left column over the right column. Odd-numbered panels display above even-numbered panels in responsive mode.

Differences With Navigation And Sidebar Menu Items

When it renders, a Client Area homepage panel resembles a panel in the sidebar. It uses the same underlying structure as the menu item objects that render the sidebar with a few changes:

Linking

A homepage panel's label is not a clickable link. Setting a URI on a homepage panel has no effect in WHMCS.

Custom Colors

Panels can render in a custom color when you define the color menu item attribute.

The following colors are available:

  • gold
  • green
  • red
  • blue
  • orange
  • pink
  • purple
  • lime
  • magenta
  • teal
  • turquoise
  • emerald
  • amethyst
  • wet-asphalt
  • midnight-blue
  • sun-flower
  • pomegranate
  • silver
  • asbestos

Optional Button

Each homepage panel has an optional button that renders to the right of the panel's label and badge.

Define the following menu item extras to render a button in a homepage panel:

  • btn-link — The URL to load in the user's web browser when the viewer clicks the button.
  • btn-text — The text within the button.
  • btn-icon — An optional Font Awesome icon to display to the left of the button's text.
  • colspan — In WHMCS 8.5 and later, an optional Boolean value that causes the panel to span both columns.

Default Panels

The following panels are defined by default. Hooks can register additional panels as well as interact with the default ones, so there is no guarantee that these panels will be visible or use this display order.

In addition, most of the panels are conditional and require the user to have the appropriate permissions.

Name Order Required Permission Conditions for Display
Unpaid Invoices 10 Invoices At least one unpaid invoice with no overdue invoices
Overdue Invoices 10 Invoices At least one overdue invoices
Domains Expiring Soon 50 Manage Domains At least one domain expiring within 45 days
Active Products/Services 100 Manage Products None
Recent Support Tickets 150 Support Tickets None
Register a New Domain 200 Orders Domain registration enabled
Your Files 250 None At least one file associated with the client's account
Affiliate Program 300 Affiliate An active affiliate account
Recent News 500 None None

Interacting With Homepage Panels

You can use WHMCS’ add_hook() function to call custom code when WHMCS is rendering homepage panels.

  • The ClientAreaHomepagePanels hook allows you to manipulate the Client Area homepage's panels.
    • Call this hook before you assign the panel object to the view template.
    • This hook passes the Client Area home panel's root item to the hook function.
  • For more information about using the hook system and supported hook functions, see our Developer Documentation.

In WHMCS 8.5 and later, you can use the CustomActions server module function to define items that perform a set function and then redirect the user to a specified URL.

  • Customers can invoke items from within the Client Area.
  • Use this to specfically add items to the My Active Products/Services panel in the Client Area home page.
  • For more information on using custom actions, see our Developer Documentation.
  • You can also use this to add custom actions to Client Area service sidebar menus.

Examples

Add a panel to the homepage

The WHMCS 6 client area homepage with a custom local temperatures panel highlighted.
This example makes use of a free third-party service that is not part of WHMCS. WHMCS cannot guarantee the state of this service and uses it for example purposes only.

This example uses the ClientAreaHomepagePanels hook and the menu item's addChild() and moveToFront() methods. The WHMCS\User\Client class contains the information to query for this example's weather data. This calls the United States National Weather Service's National Digital Forecast Database web service and requires SOAP support in your PHP installation. It also uses the Carbon library for date manipulation and display. The Carbon library is bundled with WHMCS 6.0 and later.

To add this panel to the client area homepage:

  1. Translate the logged in user's ZIP code into a latitude-longitude pair.
  2. Send the user's latitude-longitude pair to the NDFD service to retrieve their local forecast.
  3. Add a Local Temperatures child panel to the homepage panels list with today's temperatures in the panel's body HTML.
  4. Add child items to the panel for the next five days of temperatures. WHMCS will display these temperatures in a list inside the panel.
  5. Move the local temperatures to the beginning so that they display first.

Create the includes/hooks/clientWeatherPanel.php file in your WHMCS installation and enter the code below. WHMCS will parse the file and hook when the page loads. It will run the hook function when the client visits the homepage after logging in.

<?php
 
use Carbon\Carbon;
use WHMCS\Authentication\CurrentUser;
use WHMCS\View\Menu\Item;
 
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
    /** @var \WHMCS\User\Client $currentUser */
    $currentUser = CurrentUser::client();
    $today = Carbon::now()->startOfDay();
 
    // Connect to the United States' National Weather Service.
    // See http://graphical.weather.gov/xml/ for more information.
    $soapClient = new SoapClient('http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl');
 
    // The weather API takes a latitude/longitude pair as input. Translate the
    // current user's zip code into a coordinate pair.
    $response = simplexml_load_string($soapClient->LatLonListZipCode($currentUser->postcode));
    list ($latitude, $longitude) = explode(',', $response->latLonList);
 
    // Query for the weather forecast and turn it into display data.
    $response = simplexml_load_string($soapClient->NDFDGen($latitude, $longitude, 'glance'));
    $maximumTemperatures = (array)$response->data->parameters->temperature[0]->value;
    $minimumTemperatures = (array)$response->data->parameters->temperature[1]->value;
 
    // Build the new temperature panel by adding a child panel to the panel
    // list.
    $todaysMaximum = $maximumTemperatures[0];
    $todaysMinimum = $minimumTemperatures[0];
 
    $weatherPanel = $homePagePanels->addChild('local temperatures', array(
        'label' => 'Local Temperatures',
        'icon' => 'fa-cloud',
        'extras' => array(
            'color' => 'blue',
        ),
        'bodyHtml' => "<p>Today's temperature in {$currentUser->city}: {$todaysMinimum}°F / {$todaysMaximum}°F</p>",
    ));
 
    // Add the 5-day temperature forecast as child items to the panel so WHMCS
    // can present them nicely in a list.
    for ($i = 1; $i <= 5; $i++) {
        $day = $today->addDays(1);
        $minimumTemperature = $minimumTemperatures[$i];
        $maximumTemperature = $maximumTemperatures[$i];
 
        $weatherPanel->addChild($day->format('l, F j'), array(
            'label' => $day->format('l, F j'),
            'icon' => 'fa-angle-double-right',
            'badge' => "{$minimumTemperature}°F / {$maximumTemperature}°F",
            'order' => $i,
        ));
    }
 
    // Finally, move the panel to the beginning of the panel list so it's
    // displayed first.
    $weatherPanel->moveToFront();
});

Add a promotional offer panel

The WHMCS 6 client area homepage in responsive mode with custom special offer panel highlighted.
Like the previous example, this example uses the ClientAreaHomepagePanels hook and the menu item's addChild() method. Unlike the previous example, it doesn't list child items but will use a panel's body HTML and custom button in the corner.

To add this panel to the client area homepage:

  1. Add a child panel to the homepage panels list that has the the following extras:
    • A btn-link extra containing a link to the special promo.
    • A btn-text extra containing the text of the button.
  2. Define body and footer HTML in the panel to make the promotion conform to WHMCS' look and feel.
  3. Set the order to 20 to place it after the default unpaid and overdue invoice panels.

Create the includes/hooks/specialOfferPanel.php file in your WHMCS installation and enter the code below. As with the previous example, WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.

<?php
 
use WHMCS\View\Menu\Item;
 
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
    $thankYouMessage = <<<EOT
<p>Thanks for beta testing our latest offerings! To show our appreciation we'd
like to provide next month of service <strong>on the house</strong>.</p>
EOT;
 
    // Add a homepage panel with a link to a free month promo and mode it to the
    // front of the panel list.
    $homePagePanels->addChild('thanks', array(
        'label' => 'Thanks for the help!',
        'icon' => 'fa-thumbs-up',
        'order' => 20,
        'extras' => array(
            'color' => 'gold',
            'btn-link' => 'https://example.org/free-month-promo',
            'btn-text' => 'Redeem Your Free Month',
            'btn-icon' => 'fa-arrow-right',
        ),
        'bodyHtml' => $thankYouMessage,
        'footerHtml' => 'Act fast! This offer expires soon!',
    ));
});

Modifying an existing panel

Another common item is to want to change a link button and its text in a home panel panel (for example: if you want to link to a third party ticket system you already have in place.

Create the includes/hooks/recentTicketsPanel.php file in your WHMCS installation and enter the code below. As with the previous example, WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.

<?php
  
// This hook will adjust the button in the homepage panels. You have two
// different options of setExtra() or setExtras(). Use of setExtras() requires
// passing all 'extra' related vars through the array.
  
use WHMCS\View\Menu\Item;
  
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) {
    $recentTicketsPanel = $homePagePanels->getChild('Recent Support Tickets');
      
    if (!is_null($recentTicketsPanel)) {
        $recentTicketsPanel->setExtras(
            [
                'color' => 'amethyst',
                'btn-text' => 'New Name Here',
                'btn-link' => 'http://newlinkgoes.here',
                'btn-icon' => 'fa-thumbs-o-down',
            ]
        );
    }
});

Rearranging an existing panel

You may wish to change the order in which a panel appears within the Client Area.

Create the includes/hooks/rearrangeRegisterDomainPanel.php file in your WHMCS installation and enter the code below. As with previous examples, WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.

<?php
   
// This hook will rearrange the Register a New Domain panel
// to be the first panel displayed in the client area
 
use WHMCS\View\Menu\Item;
    
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) {
    if (!is_null($homePagePanels->getChild('Register a New Domain'))) {
        $homePagePanels->getChild('Register a New Domain')
        ->setOrder(0);
    }
});

Removing an existing panel

You may wish to remove a panel from the client area.

Create the includes/hooks/removeRegisterDomainPanel.php file in your WHMCS installation and enter the code below. As with previous examples, WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.

<?php
   
// This hook will remove the Register a New Domain panel from the client area
 
use WHMCS\View\Menu\Item;
    
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) {
    if (!is_null($homePagePanels->getChild('Register a New Domain'))) {
        $homePagePanels->removeChild('Register a New Domain');
    }
});

Creating a two-column panel

You may wish to create a two-column panel above the one-column panel layout, or convert an existing panel.

To do this, create the includes/hooks/fullWidthRegisterDomainPanel.php file in your WHMCS installation and enter the code below. WHMCS will parse the file and hook when the page loads and will run the hook function when the client visits the homepage after logging in.

<?php
 
// This hook causes the Register a New Domain panel to be a two-column panel.
 
use WHMCS\View\Menu\Item;
 
add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) {
 if (!is_null($homePagePanels->getChild('Register a New Domain'))) {
 $homePagePanels->getChild('Register a New Domain')->setExtra('colspan', true);
 }
});