Extending Further
Custom functions allow you to define extra operations that can be performed using the module. The custom functions can perform actions, or define extra client area pages/output. Permissions can be granted for who can use each custom function, be it just clients, just admins, or both.
The convention for custom function names follow the same as any other function of a module. It must begin with yourmodule_, and then the custom function name
The easiest way to show this is with an example. So let’s take an example of a custom Function that will use a template, customdomain.tpl.
<?php
function yourmodule_custom($params)
{
$domainid = $params['domainid'];
$sld = $params['sld'];
$tld = $params['tld'];
return [
'template' => 'customdomain',
'vars' => [
'var1' => 'value here',
'var2' => 'another value here',
],
];
}
The above shows how to define custom functions, use the parameters passed, and return an array response. The response can either be a simple empty array/error for an action function, or a complex array return like the above to define an extra client area page for extra domain management functionality.
Now we need to allow clients to use this. The following function defines that clients are allowed to invoke the push function, and will add a menu option to the Domain Actions dropdown within the client area for it:
<?php
function yourmodule_ClientAreaCustomButtonArray($params)
{
$buttons = [
"Custom Domain" => "custom",
];
return $buttons;
}
The key value of the
array
is what displays to admins and clients on the button or menu options for the commands. The value is the custom function name without the modulename_
prefix.A description of how to provide a button or way to invoke a custom function is in the Client Area Output section:
<form method="post" action="">
<input type="hidden" name="id" value="{$domainid}" />
<input type="hidden" name="modop" value="custom" />
<input type="hidden" name="a" value="custom" />
<input type="submit" value="Custom Domain" />