{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Custom Actions","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-actions","__idx":0},"children":["Custom Actions"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["We added this functionality in WHMCS 8.5."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Custom actions allow you to define a list of items that perform a function and redirect the user to a specified URL. You can limit access to a custom action based on the user-level ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["productsso"]}," permission."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Clients can perform actions from within the Client Area. When a client does this, it invokes the defined function. After the function completes and returns the structured response, a browser window will open to the location in that response."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Currently, you can use this to add buttons to the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Active Products/Services"]}," panel on the Client Area homepage and add items to the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Actions"]}," sidebar menu."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"customactions-function","__idx":1},"children":["CustomActions Function"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CustomActions"]}," function is responsible for returning the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["WHMCS\\Module\\Server\\CustomActionCollection"]}," object."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This object is a collection of ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["WHMCS\\Module\\Server\\CustomAction"]}," objects that represent each individual item to display in the Client Area."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For more information on both the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CustomActionCollection"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CustomAction"]}," classes, see the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["WHMCS\\Module\\Server"]}," namespace at https://classdocs.whmcs.com/."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following example creates a simple ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CustomActions"]}," function that returns a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CustomActionCollection"]}," object."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"<?php\n\nuse WHMCS\\Module\\Server\\CustomAction;\nuse WHMCS\\Module\\Server\\CustomActionCollection;\n\n/**\n * Define a collection of Custom Action items to be displayed in the Client Area.\n *\n * Called when rendering Custom Action items in the Client Area; currently\n * limited to the \"Active Products/Services\" Client Area homepage panel.\n *\n * Use to provide authenticated Client Area users with the ability to perform a predefined\n * action at the click of a button. The action can be provided either in the form of a custom\n * module function or an anonymous function. For example, this can be used to provide a\n * Single Sign On button.\n *\n * @param array $params Common module parameters\n *\n * @see https://developers.whmcs.com/provisioning-modules/module-parameters/\n *\n * @return CustomActionCollection\n */\nfunction provisioningmodule_CustomActions(array $params): CustomActionCollection\n{\n    // Instantiate a new CustomActionCollection to house the CustomAction objects.\n    $customActionCollection = new CustomActionCollection();\n\n    // Add a new CustomAction object to the collection.\n    $customActionCollection->add(\n        CustomAction::factory(\n            'provisioningmodule',\n            'Log in to Demo Provisioning Module',\n            'provisioningmodule_ServiceSingleSignOn',\n            [$params],\n            ['productsso'],\n            true\n        )\n    );\n\n    // An anonymous function can be used in place of a custom module function.\n    $customActionCollection->add(\n        CustomAction::factory(\n            'provisioningmodule',\n            'Visit the WHMCS Website',\n            function () {\n                return [\n                    'success' => true,\n                    'redirectTo' => '//www.whmcs.com/',\n                ];\n            }\n        )\n    );\n\n    // Return the CustomActionCollection to be used when checking for CustomAction items to render.\n    return $customActionCollection;\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"callable-function","__idx":2},"children":["Callable Function"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CustomAction"]}," object expects you to provide a callable function upon creation. This is the logic that the system will execute when a customer interacts with the item in the Client Area."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The expected return for this function is an array that indicates success and provides either the redirect URL or an error message."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"success-example","__idx":3},"children":["Success Example"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"[\n\t'success' => true,\n\t'redirectTo' => 'https://whmcs.com/',\n]\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"failure-example","__idx":4},"children":["Failure Example"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"[\n\t'success' => false,\n\t'errorMsg' => 'This is an error message.',\n]\n"},"children":[]}]},"headings":[{"value":"Custom Actions","id":"custom-actions","depth":1},{"value":"CustomActions Function","id":"customactions-function","depth":2},{"value":"Callable Function","id":"callable-function","depth":2},{"value":"Success Example","id":"success-example","depth":3},{"value":"Failure Example","id":"failure-example","depth":3}],"frontmatter":{"title":"Custom Actions","seo":{"title":"Custom Actions"}},"lastModified":"2026-08-03T17:00:42.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/provisioning-modules/custom-actions","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}