Creating a New Plugin

Overview

Plugins can be used to enhance one-on-one and chatrooms functionality.

Plugin development requires working knowledge of PHP and JavaScript. Take a few minutes going through the PHP and JS API.

Workflow

1. When the user clicks on a plugin, the `init()` function is called and the user’s ID is sent as a parameter. In case of chatrooms, the chatroom ID is sent as a parameter
2. Using the ID and AJAX, PHP files can be called and functionality can be added accordingly.
3. To get the logged in user’s ID, PHP must be used.

Creating your first plugin

Hello world

1. Create a new folder in plugins directory e.g. sample
2. Create a 16×16 icon and upload it as plugins/sample/icon.png
3. Add code.php file with the following contents

<?php $plugininfo=array(‘sample’,’Sample Plugin’);

4. Create a init.js file with the following contents

(function($) {
    $.ccsample = (function() {
        var title = ‘Activate Sample Plugin’;
        return {
            getTitle: function() {
                return title;
            },
            init: function(id) {
                baseUrl = $.cometchat.getBaseUrl();
                alert(‘Hello world’);
            },
    };
    })();
})(jqcc);

5) Add the following to /cometchat/themes/<theme_name>/css/cometchat.css and /cometchat/admin/css/admin.css files:

.cometchat_sample {
    background: url(‘plugins/sample/icon.png’) no – repeat top left;
    width: 16 px;
    height: 16 px;
}

6) Login to CometChat Administration Panel->Settings->Clear Cache->Click on “Clear Cache” button

Not finding what you need?

The CometChat team is here to help!