Snapin Plugin Development Guide

  • March 21, 2022
  • 0 Comments

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

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

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.

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

How helpful was this article to you?

Posting has been disabled.