Skip to content

Instantly share code, notes, and snippets.

@klaude
Created December 15, 2015 21:53
Show Gist options
  • Select an option

  • Save klaude/e1e69b9d482d3a9879b5 to your computer and use it in GitHub Desktop.

Select an option

Save klaude/e1e69b9d482d3a9879b5 to your computer and use it in GitHub Desktop.

Revisions

  1. klaude created this gist Dec 15, 2015.
    51 changes: 51 additions & 0 deletions add-unban-ip-link.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    <?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];
    });