How to Create a Custom PHP Page for WHMCS?

Create a PHP file

> Please login to your cPanel account

> Please go to the file manager

> Please go to the WHMCS root directory

> Please click on the File button.

> Please enter the name of the file in the pop-up 

> Please click the Create New File button.

Add PHP code

> Please go to the File Manager

> Please Navigate to your WHMCS root directory

> Please open the .php file you created in the previous section you can right-click on it, then click on Edit 

> Please copy and paste the following code to the file



<!--?php

use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

define('CLIENTAREA', true);

require __DIR__ . '/init.php';

$ca = new ClientArea();

$ca--->setPageTitle('Your Page Title Goes Here');

$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('mypage.php', 'Your Custom Page Name');

$ca->initPage();

//$ca->requireLogin(); // Uncomment this line to require a login to access this page

// To assign variables to the template system use the following syntax.
// These can then be referenced using {$variablename} in the template.

//$ca->assign('variablename', $value);

// Check login status
if ($ca->isLoggedIn()) {

/**
* User is logged in - put any code you like here
*
* Here's an example to get the currently logged in clients first name
*/

$clientName = Capsule::table('tblclients')
->where('id', '=', $ca->getUserID())->pluck('firstname');
// 'pluck' was renamed within WHMCS 7.0. Replace it with 'value' instead.
// ->where('id', '=', $ca->getUserID())->value('firstname');
$ca->assign('clientname', $clientName);

} else {

// User is not logged in
$ca->assign('clientname', 'Random User');

}

/**
* Set a context for sidebars
*
* @link https://docs.whmcs.com/Editing_Client_Area_Menus#Context
*/
Menu::addContext();

/**
* Setup the primary and secondary sidebars
*
* @link https://docs.whmcs.com/Editing_Client_Area_Menus#Context
*/
Menu::primarySidebar('announcementList');
Menu::secondarySidebar('announcementList');

# Define the template filename to be used without the .tpl extension

$ca->setTemplate('mypage');

$ca->output();

 

 

> Please click on the save changes button

 

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Access MailServer Configuration Options?

> Please login to your WHM account > Please Search for “mailserver”  > Please click on...

How to Switch Mailserver Between Mdbox and Maildir in WHM?

> Please login to your cPanel account > Please search for the “mailbox” in the search box...

How to configure the exim settings with the basic editor?

> Please login to your WHM account > Please search with “exim” in the search box >...

How to configure the exim settings with the Advance editor?

> Please login to your WHM account > Please search with  “exim” in the serch box >...

How to Backup Exim Configuration?

> Please login to your WHM account > Please search “exim” in the search box > Please...

Powered by WHMCompleteSolution