Get a quoteGet a quote
Live ChatLive chat
Client ZoneClient Zone
ContactsContacts
Hide
Live Support
Sales department
Technical Support
How to write your own plugin for cPanel

To write your own plugin for cPanel it is not necessary to be a system administrator or a cPanel guru. Anyone, who can write code in PHP should be able to handle this task easily. Our first plugin was written within a day. With this how-to guide you will be able to do this within about 20 minutes. Let’s begin.

To get started you will need a good idea for a plugin. If you do not have one, do not waste time. In this how-to guide, our idea is to make a magic button which displays “First cPanel Plugin!” when you click on it.

We also need to find a name for our plug-in. Draw an icon for it and choose group from the cPanel menu. Now we can start programming. We will name our plugin “magic_button”. We are not designers so we will just pick one icon from a very useful site: iconfinder.com. Ok here is our nice icon magic button. Note that the icon should be 32×32x. Which group in the menu should we choose? Well, let’s choose “Files”. Now we have all we need to generate the install file for our plug-in. You can use the online generator here. We have generated the following magic_button.cpanelplugin:

#cpanel plugin file 1.0 (for use with /usr/local/cpanel/bin/register_cpanelplugin)
version: 1.0
name:magic_button
description:magic button plugin
featuremanager:1
url:magic_button/index.php
acontent:
onclick:
if:
itemorder:999
itemdesc:Magic Button
group:files
image:iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAG0ElEQVRIx7VWS3NUxxXu5+2+985o
XpqrkRkjJI3BJsaJiXGAuIAqF5Wtk0oWNlnAjqLiqvgX2ElsKokTZ2+cip2VU0UWwakiQoQCl0Cl
CCEkJTYgHpZGDxCakWbm3rlz+/YjizGQGBF5Eb5VL7rPd7rPOd/X0BgDHicQeMx47ATk/x6x4fvX
pq8jhPt6e1IdHWsQCCFu3bw5MzPbqNe1VpgQx3Y6Uh3ZbDbveel0GmO8Zujx8fETJz45cOBAqb/v
X599pqT86g183z996tT09HQQNMOwKUSstQIAIIQQwoQQSgnnPJFI5D2vWCz29fU9sWGDMeZPH388
NTWljPnH6Ch37O/t3797586vPtHYxYsnT56sVqq+79drtaDZFEJYjAFgAACm3W3GAAAQhIxzzngy
mSwUCpRZM7OzIyMjO1544a8nTiSTyf9MGrYPnh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kRPtUNputVCrr+0EU
RQsLC5ZlYYxrrdaVq1eDoHF3aamr+wmvq5DvKjT9xly5vDA/d2dxcaZchgAwzjHGWuuvZTg3btxQ
SrVr2l0ouIlEwnUJIbEQsZTpVDqOIsaY6yby+Ty1rNVaLZaxVhoTvLS05HneOpZ5+fLlL7vTGEpp
Mpn0PK9Q6O7u7u7M5TBGEELXdTOZTCqddhyHEAIAUFoxxi5durS+J4+NjWmtlVLq3pURQoQQSul9
I0MIYYwRQm3NUEorKRGEx48fX59g9OJoFEVtjvX9FwIDjJSxVErE8dilsf9FoLUeHx8vz5Z93//6
nyUIADBGK92o15fuLA2dH5JSrk3QbDbPnz9frVaFEARjSgh6hLk/gAEYE8tihJBmq1WtVs+dPReG
4doEUsrOzk4ppTEGE8IYa0sbuicY/5U4BAghalHGGWMWJthorbXuKnS1vW8NAsuynv3GswcPHlRK
CSEQxoQQQgjGGEJk7gEAA4yBEGFCKLUooQjhKIqMMYcOHXr+W88zxtaeA8ZYobtw+PDhUql07Nix
crkMjOGMSSWlknEsxZeIYynjOJZxLKJodXV1ZWWluGHDT15/fd++fZ7n2bb9SKnQWtfr9TAMV1ZW
hoaGBgcHv7h1SyvlOG4i2ZHKZB3XbQZBo16r12pR1EII9fb17tm756XvvpTL5WzHTiaS7cl4pBYZ
Y6SUbaOP49j3/Tt37ty+fbtWq4etsF1Y2+bpdNrzPM/zOjo6CCUYYcYYIeThcsFHdaTWuj3P9zfc
X9yP0rZ+hFB76NbEvwExt61Y1K/0dQAAAABJRU5ErkJggg==

This file should be uploaded in the cPanel directory /usr/local/cpanel/bin/ and then registered in cPanel. This can be done with following command:

/usr/local/cpanel/bin/register_cpanelplugin /usr/local/cpanel/bin magic_button.cpanelplugin.

Once the plugin is registered, then we can open cPanel, and see our cute icon in the menu.
cpanel menu

However, if we click on it now, we will get an error “Not Found” message. The thing is that the installer does not build folder structure for us, we will have to do it. So let’s now create a directory:

mkdir /usr/local/cpanel/base/frontend/x3/magic_button.

Then create the script:

touch /usr/local/cpanel/base/frontend/x3/magic_button/index.php.

At this point we are ready to write a PHP script. You should always use full PHP tag withing cPanel plugins. Here is the code:

<?php
echo "<form name='magicform' id='magic' method='post'>
 <input value='magic' name='action' type='hidden'>
 <input class='input-button' value='Do the magic' type='submit'>
</form>\n";
if(!empty($_POST['action'])) {
 echo "<h1>First cPanel Plugin!</h1>\n";
}
php?>

Now we can open cPanel https://host:2083/frontend/x3/magic_button/index.php and test our magic plugin.
magic plugin

Ok it worked, what about cPanel appearance? To make our plugin more native we will add some cPanel’s API calls to the top and the end of the script. The full code will appear as follows:

<cpanel setvar="headerimg=../images/tools.gif">
<cpanel setvar="dprefix=../">
<cpanel Branding="include(stdheader.html)">
<div>
<style>
<?cp Branding::spritelist(
.spriteicon_img_mini {
 float:left;margin-right:5px;
 background: url\{leftparenthesis}%\{rightparenthesis};
 }
 %,spriteurl,images::#icon-${img}_mini 
 {background-position\{colon}0 -${cssposition}px;
 width\{colon}${width}px;height\{colon}${height}px; }:)
 imgtype=icon,subtype=img,method=scale_60percent,format=png,img=hd ?>
</style>
<div id="h1Title">
<div id="icon-hd_mini"></div>
<cpanel langprint="Magic Button"></div>
<?php
echo "<form name='magicform' id='magic' method='post'>
 <input value='magic' name='action' type='hidden'>
 <input class='input-button' value='Do the magic' type='submit'>
</form>\n";
if(!empty($_POST['action'])) {
 echo "<br><div class='highlight'>First cPanel Plugin!</div>\n";
}
php?>
</div>
<cpanel Branding="include(stdfooter.html)">

cpanel plugin
Of course, for more complex plugins, you will need to think about things such as: a full installer, updater, and so on. Here is link to the official documentation and a link to the forum where you can always go to ask for help.

Request a Quote
Request a quote
Fill out a small form and let us contact you shortly
Client Zone
Access Client Zone
Ticket system, knowledge base and other services for our clients
Contact Us
Contact us
Send us a request or ask any questions via this contact form