{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Custom Functions","description":"Developer documentation for the WHMCS API — the","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"custom-functions","__idx":0},"children":["Custom Functions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Custom functions allow you to define operations that run using the module."," ","The custom functions can perform actions or define additional Client Area pages or output."," ","Permissions can be granted for who can use each custom function (just clients, just admins, or both)."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The convention for custom function names is the same as any other module function."," ","It must begin with the module filename (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["filename_"]},") and the custom function name."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"example-custom-function","__idx":1},"children":["Example Custom Function ",{"$$mdtype":"Tag","name":"a","attributes":{"id":"example-function"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Consider the following example of a reboot and shutdown function in a VM or VPS system:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"function mymodule_reboot($params) {\n\n\t# Code to perform reboot action goes here...\n\n    if ($successful) {\n\t\t$result = \"success\";\n\t} else {\n\t\t$result = \"Error Message Goes Here...\";\n\t}\n\treturn $result;\n\n}\n\nfunction mymodule_shutdown($params) {\n\n\t# Code to perform shutdown action goes here...\n\n    if ($successful) {\n\t\t$result = \"success\";\n\t} else {\n\t\t$result = \"Error Message Goes Here...\";\n\t}\n\treturn $result;\n\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The above example defines a custom function and uses the passed variables."," ","The custom function returns either ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["success"]}," or an error message to indicate failure."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following example allows clients to perform reboots but only allows admins to perform a reboot or shutdown:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"function mymodule_ClientAreaCustomButtonArray() {\n    $buttonarray = array(\n\t \"Reboot Server\" => \"reboot\",\n\t);\n\treturn $buttonarray;\n}\n\nfunction mymodule_AdminCustomButtonArray() {\n    $buttonarray = array(\n\t \"Reboot Server\" => \"reboot\",\n\t \"Shutdown Server\" => \"shutdown\",\n\t);\n\treturn $buttonarray;\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["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 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["modulename_"]}," prefix."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A description of how to provide a button or way to invoke a custom function is in the Client Area Output section:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"<form method=\"post\" action=\"clientarea.php?action=productdetails\">\n<input type=\"hidden\" name=\"id\" value=\"{$serviceid}\" />\n<input type=\"hidden\" name=\"modop\" value=\"custom\" />\n<input type=\"hidden\" name=\"a\" value=\"reboot\" />\n<input type=\"submit\" value=\"Reboot VPS Server\" />\n</form>\n"},"children":[]}]},"headings":[{"value":"Custom Functions","id":"custom-functions","depth":1},{"value":"Example Custom Function","id":"example-custom-function","depth":2}],"frontmatter":{"title":"Custom Functions","seo":{"title":"Custom Functions"}},"lastModified":"2026-08-03T17:00:42.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/provisioning-modules/custom-functions","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}