> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://docs.clientexec.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Snapin Plugin Development Guide

A snapin plugin allows you to extend the functionality of Clientexec. It can be used to create new pages and actions, or to listen and act on events (hooks).

We have created a sample snapin plugin that can be used as a starting point: [https://github.com/clientexec/sample-snapin](https://github.com/clientexec/sample-snapin)

Once a snapin has been uploaded to your server, it can be managed at **Settings **> **Plugins **> **Snapins**.

### Naming Convention

The name of the plugin directory MUST be all lower case, and alphanumeric, such as sample.

The name of the plugin file, and the plugin class MUST start with Plugin, followed by the name of the directory with ONLY the first letter capitalized, such as PluginSample

![](https://storage.crisp.chat/users/helpdesk/website/895a2775afb3f800/sample_yvsdtm.png)

### Configuration

Each server plugin must have a getVariables() function which will define options for each server and package. The function must return an array of values.

```html
public function getVariables()
{
    $variables = [
        'Plugin Name' => [
            'type' => 'hidden',
            'description' => 'Used by CE to show plugin',
            'value' => 'Sample'
        ],
        'Text Field' => [
            'type' => 'text',
            'description' => 'Text Field Description',
            'value' => 'Default Value',
        ],
        'Encrypted Text Field' => [
            'type' => 'text',
            'description' => 'Encrypted Text Field Description',
            'value' => '',
            'encryptable' => true
        ],
        'Password Text Field' => [
            'type' => 'password',
            'description' => 'Encrypted Password Field Description',
            'value' => '',
            'encryptable' => true
        ],
        'Text Area' => [
            'type' => 'textarea',
            'description' => 'Text Area Description',
            'value' => 'Default Value',
        ],
        'Yes / No' => [
            'type' => 'yesno',
            'description' => 'Yes / No Description',
            'value' => '1',
        ],
        'Actions' => [
            'type' => 'hidden',
            'description' => 'Current actions that are active for this plugin per server',
            'value'=>'Create,Delete,Suspend,UnSuspend'
        ],
        'Registered Actions For Customer' => [
            'type' => 'hidden',
            'description' => 'Current actions that are active for this plugin per server for customers',
            'value' => 'authenticateClient'
        ],
        'package_addons' => [
            'type' => 'hidden',
            'description' => 'Supported signup addons variables',
            'value' => ['DISKSPACE', 'BANDWIDTH', 'SSL']
        ],
        'package_vars' => [
            'type' => 'hidden',
            'description' => 'Whether package settings are set',
            'value' => '1',
        ],
        'package_vars_values' => [
            'type'  => 'hidden',
            'description' => lang('Package Settings'),
            'value' => [
                'Text Field' => [
                    'type' => 'text',
                    'label' => 'Text Field Label',
                    'description' => 'Text Field Description',
                    'value' => 'Default Value',
                ],
                'Drop Down' => [
                    'type' => 'dropdown',
                    'multiple' => false,
                    'getValues' => 'getDropDownValues',
                    'label' => 'Drop Down Label',
                    'description' => 'Drop Down Description',
                    'vaue' => '',
                ]
            ]
        ]
    ];

    return $variables;
}
```

### Error Handling

Throwing a CE_Exception will display the error message to the client/admin.

### Functions

Each snapin should have an init() function, which will call internal functions to determine what the snapin does.

### addMappingForTopMenu($type, $loc, $tpl, $title, $desc)

Calling this function will add a new view to the top menu of either the admin or client.

| **VARIABLE** | **DESC** | **INFO** |
| -------- | -------- | -------- |
| **$type**    | The type of the view.    | admin or public.    |
| **$loc**    | Menu location.    | **Admin area options:** clients, billing, support, tools (default) **Client area options:**  products, profile, billing, support, tools (default)    |
| **$tpl**    | The template to be rendered.    |
| **$title**    | The title to use in the top menu.    |
| **$desc**    | The description to use in the snapin settings.  |



