A Beginner’s Guide To Develop osTicket’s Plugin

Create new plugins to add custom features into your osTicket installation. Add enhanced functionality to meet needs and requirements of your agents and customers.

A beginner's guide to develop osTicket's plugin

osTicket is an open source ticketing based helpdesk system designed for customers to report their queries and complaints to support staff. It provides easy to use inquires management module that converts inquiries coming from phone, email and forms into web-based tickets. It offers wide range of features and options that enables support staff to provide incredible client support experience for customers. osTicket is an entirely flexible support ticket framework that offers numerous options to help tailor all parts of client support experience like messages sent to client, pages and notifications. We will discuss following topics in this tutorial:

Why to Use Plugins?

In this topic we will learn how to create a simple plugin to extend osTicket’s core functionality. A plugin is a piece of software, that extends the core functionality of any app/software. Following are some reasons for apps to support plugins:

  • It allows third party developers to create software components which extend the functionality of an application.
  • Plugins allow to easily integrate new features.
  • Also it doesn’t increase the size and complexity of an application.
  • As well as developers can keep and manage plugins’ code separately from core application.

Requirements

  • PHP version 5.6 or above
  • osTicket installation
  • Basic PHP Knowledge

How to Develop osTicket’s Plugin?

  • Create plugin’s folder in <ROOT>/include/plugins directory. In this tutorial we will create a demo plugin which integrates osTicket with Redmine.
  • It should have following necessary files: plugin.php and config.php.
  • plugin.php file contains general description of the plugin. Use following sample code in plugin.php file:
<?php

return array(
    'id' =>             'dynabic:redmine', # notrans
    'version' =>        '0.1',
    'name' =>           /* trans */ 'Dynabic Redmine',
    'author' =>         'Bilal Kiani',
    'description' =>    /* trans */ 'Integration with Dynabic.Redmine',
    'url' =>            '',
    'plugin' =>         'redmine.php:DynabicRedminePlugin',
);

?>
  • Then replace id, name, author name and plugin class names from above code.
  • After that, we need to display plugin configuration options into osTicket’s backend. Add following sample code into config.php file.
<?php
require_once INCLUDE_DIR . 'class.plugin.php';
class DynabicRedminePluginConfig extends PluginConfig {

    // Provide compatibility function for versions of osTicket prior to
    // translation support (v1.9.4)
    function translate() {
        if (!method_exists('Plugin', 'translate')) {
            return array(
                function($x) { return $x; },
                function($x, $y, $n) { return $n != 1 ? $y : $x; },
            );
        }
        return Plugin::translate('dynabic-redmine');
    }

    function getOptions() {
        list($__, $_N) = self::translate();        
        return array(
            'dynabicRedmineCredentials' => new SectionBreakField(array(
                'label' => $__('Redmine Credentials')
            )),
            'dynabic-Redmine-username' => new TextboxField(array(
                'label' => $__('Username'),
                'configuration' => array('size'=>60, 'length'=>100),                
            )),
            'dynabic-Redmine-password' => new PasswordField(array(
                'label' => $__('Password'),
                'configuration' => array('size'=>60, 'length'=>100),                
            )),
        );
    }
}
  • As a result, this will create username and password fields on config page as shown here:
A Beginner’s Guide To Develop osTicket’s Plugin
  • The following is a list of class fields that are available, they are defined in [INSTALL_ROOT]/include/class.forms.php:
    • TextboxField – text box
    • TextareaField – text area
    • ThreadEntryField – rich text area, used for discussion threads
    • DatetimeField – JQuery datepicker
    • PhoneField – text box optimized for phone numbers
    • BooleanField – checkbox
    • ChoiceField – drop-down select field
    • SectionBreakField – horizontal section break
  • After that, we need to create the file where plugin’s functionality will be defined.
  • File name should be same as defined in plugin.php file. i.e redmine.php.
  • This will must hold the class DynabicRedminePlugin. Check out following sample code:
class DynabicRedminePlugin extends Plugin {
    var $config_class = "DynabicRedminePluginConfig";
	 /**
     * The Redmine WSDL endpoint.
     */

    function bootstrap() {
        $config = $this->getConfig();
        # ----- Dynabic.Redmine credentials ---------------------
        $dynabicRedmine = json_decode($config->get('dynabicRedmine-enabled'));
		define('Redmine_USERNAME', $config->get('dynabic-Redmine-username'));
		define('Redmine_PASSWORD', $config->get('dynabic-Redmine-password'));
    }
  • This code fetched the configuration values and you can use these values in your functions. In this file you can add your plugin’s functionality as your requirements.

Conclusion

Plugins are the components that extend the core functionality of any app/software. We have learnt how to add custom feature and enhancements in osTicket by creating a sample plugin. To learn more about osTicket, please visit following guides:


Popular Free Ticketing Based Helpdesk and Customer Care System

How To Set Up Help Desk System Using osTicket