Show Credentials on WHMCS Product Page
Added by astuffedtiger on May 16, 2017 19:36
<?php
    use WHMCS\View\Menu\Item as MenuItem;
    /* Add credentials to the end of all secondary sidebars. */
    add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar)
    {
        /* Get the credentials. */
        $service = Menu::context('service');
        $username = "{$service->username}";
        $password = "{$service->password}";
        $password = decrypt($password);
        /* If the username isn't empty let's show them! */
        if ($username != '') {
            /*
                Add a panel to the end of the secondary sidebar for credentials.
                Declare it with the name "credentials" so we can easily retrieve it
                later.
            */
            $secondarySidebar->addChild('credentials', array(
                'label' => 'Credentials',
                'uri' => '#',
                'icon' => 'fa-desktop',
            ));
            /* Retrieve the panel we just created. */
            $credentialPanel = $secondarySidebar->getChild('credentials');
            /* Move the panel to the end of the sorting order so it's always displayed
            as the last panel in the sidebar. */
            $credentialPanel->moveToBack();
            /* Show the username. */
            $credentialPanel->addChild('username', array(
                'label' => $username,
                'order' => 1,
                'icon' => 'fa-user',
            ));
            /* Show the password. */
            $credentialPanel->addChild('password', array(
                'label' => $password,
                'order' => 2,
                'icon' => 'fa-lock',
            ));
        }
    });

Comments