Created
December 15, 2015 21:53
-
-
Save klaude/e1e69b9d482d3a9879b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add Modules Garden's Unban Center module's sidebar menu items without having | |
* to create or modify template files. | |
* | |
* @see http://docs.whmcs.com/Editing_Client_Area_Menus | |
*/ | |
add_hook('ClientAreaPage', 1, function ($templateVariables) { | |
// Look for the Unban Center's $hasUnban template variable. If it's not | |
// defined then the Unban Center might might not be loaded. | |
$hasUnban = isset($templateVariables[0]['hasUnban']) ? (bool) $templateVariables[0]['hasUnban'] : false; | |
/** @var \WHMCS\View\Menu\Item $secondarySidebar */ | |
$secondarySidebar = Menu::secondarySidebar(); | |
$myServicesActions = $secondarySidebar->getChild('My Services Actions'); | |
// Don't modify the secondary sidebar if the Unban Center module isn't | |
// loaded, if the secondary sidebar doesn't exist, or if the "My Services | |
// Actions" panel in the secondary sidebar doesn't exist. | |
if (!$hasUnban || is_null($secondarySidebar) || is_null($myServicesActions)) { | |
return []; | |
} | |
// Determine the contents of the "Unban IP Address" menu item. | |
$uri = 'index.php?m=unbanCenter'; | |
if (isset($templateVariables[0]['unbanId'])) { | |
$uri .= "&id={$templateVariables[0]['unbanId']}"; | |
} | |
$label = isset($templateVariables[0]['mglang']) | |
? $templateVariables[0]['mglang']->_('integrationbtn') | |
: 'Unban Your IP Address'; | |
// Add the "Unban IP Address" menu item to the secondary sidebar's "My | |
// Services Actions" panel. | |
$unbanIpAddress = $myServicesActions->addChild( | |
'Unban Center', | |
[ | |
'uri' => $uri, | |
'icon' => 'fa-unlock', | |
'label' => $label, | |
] | |
); | |
$unbanIpAddress->moveToBack(); | |
// Re-assign the secondary sidebar to the template. | |
return ['secondarySidebar' => $secondarySidebar]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment