Add Custom Buttons

Starting from Plesk 12.0, there is an easy way to add custom buttons related to an extension. Previously, extension developers had to use CLI or XML API calls in post-install and pre-uninstall scripts for creating custom buttons.

To add custom buttons, you need to develop a class derived from pm_Hook_CustomButtons. The class must be placed in the directory plib/hooks/. You can find the complete list of supported values for 'place' under 'Constants'.

You can set up custom buttons in the following places:

  • PLACE_COMMON - Left menu of Administrator panel
  • PLACE_ADMIN_HOME - Administrator's home page
  • PLACE_RESELLER_HOME - Reseller's home page
  • PLACE_CUSTOMER_HOME - Customer's home page
  • PLACE_ADMIN_NAVIGATION - Left navigation menu of the Administrator's panel
  • PLACE_RESELLER_NAVIGATION - Left navigation menu of the Reseller's panel
  • PLACE_ADMIN_TOOLS_AND_SETTINGS - Administrator's Tools & Settings section
  • PLACE_RESELLER_TOOLS_AND_SETTINGS - Reseller's Tools & Utilities section
  • PLACE_HOSTING_PANEL_NAVIGATION - Left navigation menu of the Customer panel and the tabs on the domains's page when a subscription is opened in the Administrator panel.
  • PLACE_DOMAIN - right sidebar on the Websites & Domains page in the Customer Panel
  • PLACE_DOMAIN_PROPERTIES - the Websites & Domains page in the Customer Panel
  • PLACE_TOOLBAR - Toolbar (usually above the List)
  • PLACE_LIST_ACTIONS - Button in the active list (except Websites & Domains)

One button can be set up for multiple places at once. In some places, you can use such optional parameters as icon and description. You can specify both local and external hyperlinks.

Depending on the location of a custom button, you can specify additional parameters for it.

  • For custom buttons located in Tools & Settings for the Plesk administrator (PLACE_ADMIN_TOOLS_AND_SETTINGS) and Tools & Utilities for resellers (PLACE_RESELLER_TOOLS_AND_SETTINGS):
    • section - the id of a section on the Tools & Settings screen in which the button must be placed. If left unspecified, the custom button will be added to the "Additional Services" section.
    • order - the position of the button in the list within the section in which it is placed ("1" for the first position in the list and so on). If left unspecified, the custom button will be added to the end of the section.
  • For custom buttons located in the left navigation menu for the Plesk administrator (PLACE_ADMIN_NAVIGATION) and the left navigation menu for resellers (PLACE_RESELLER_NAVIGATION):
    • section - the id of a section in the left navigation menu in which the button must be placed. If left unspecified, the custom button will be added to the "Links to Additional Services" section.
    • order - the position of the button in the list within the section in which it is placed ("1" for the first position in the list and so on). If left unspecified, the custom button will be added to the end of the section.
  • For custom buttons located in the left navigation menu of the Customer panel (PLACE_HOSTING_PANEL_NAVIGATION):
    • order - the position of the button in the list ("1" for the first position in the list and so on). If left unspecified, the custom button will be added to the end of the list.
  • For custom buttons located on the Websites & Domains page in the Customer Panel (PLACE_DOMAIN_PROPERTIES):
    • additionalComments - additional information clarifying the purpose of the button. Can be either single-line (string) or multi-line (array).
    • order - the position of the button in the list within the section in which it is placed ("1" for the first position in the list and so on). If left unspecified, the custom button will be added to the end of the section.

You can find the sample code in our repository here.

Example

The following examples shows how to add several custom buttons. The used method:

Use the following code:

class Modules_CustomButtons_CustomButtons extends pm_Hook_CustomButtons
{
     
    public function getButtons()
    {
        return [[
            'place' => self::PLACE_DOMAIN,
            'title' => 'Domain Button',
            'description' => 'Description for domain button',
            'icon' => pm_Context::getBaseUrl() . 'images/icon.png',
            'link' => pm_Context::getBaseUrl() . 'index.php/index/index',
        ], [
            'place' => [
                self::PLACE_HOSTING_PANEL_NAVIGATION,
                self::PLACE_ADMIN_TOOLS_AND_SETTINGS,
                self::PLACE_RESELLER_TOOLS_AND_SETTINGS,
            ],
            'title' => 'Multi Place Button',
            'description' => 'Description for multi place button',
            'link' => 'http://odin.com/',
            'newWindow' => true,
        ]];
    }
   
}
class Modules_CustomButtons_CustomButtons extends pm_Hook_CustomButtons
{
    public function getButtons()
    {
        return [[
            'place' => self::PLACE_ADMIN_TOOLS_AND_SETTINGS,
            'section' => 'toolsAndResourcesButtons',
            'order' => 1,
            'title' => 'My Button 1',
            'description' => 'Description for my button 1',
            'link' => pm_Context::getActionUrl('index', 'another'),
        ], [
            'place' => self::PLACE_ADMIN_TOOLS_AND_SETTINGS,
            'section' => 'generalButtons',
            'order' => 4,
            'title' => 'My Button 2',
            'description' => 'Description for my button 2',
            'link' => pm_Context::getActionUrl('index', 'another'),
        ]];
    }
}
 

Leave your feedback on this topic here

If you have questions or need support, please visit the Plesk forum or contact your hosting provider.
The comments below are for feedback on the documentation only. No timely answers or help will be provided.