Getting Started with Joomla Plugin Development

Plugins help web developers to improve and add features to their Joomla website. Plugins help you a lot to offer your clients or visitors the features they need such as language domains, HTTP authenticates, SSL redirection, static content, and so on.

First of all, you need to know that Joomla has 5 types of extensions: component, modules, plugins, libraries, and language files. So plugins are not components, modules, libraries or language files.

The component is representing the main functionality of a website. Modules are like search bars and other similar widgets. Plugins are working in the background using multiple processes to offer complex features.

Need a Good Joomla Web Host?

Focus on building your Joomla website, while InMotion will take care of the rest.

There are multiple plugin-groups such as authentication, content, system, user, editors, search, finder, CAPTCHA, extension, quickicon.

Authentication plugins are used to log in and log out a user on a Joomla website using a username and a password and matching them with the information from the database. An example of an application using authentication is a bridge between Joomla and Magento where the Joomla user’s password and username match with information from the Magento database. Content plugins groups are used to fetched content and display them on your screen. User plugin used also when you log in and log out. Also, when you change your user records, Joomla uses user plugins. Editors such as WYSIWYG editors or AJAX editors where you create content for your Joomla website.

There are third-party plugins where developers offer the possibility to extend their functionality making them open source and sometimes even free. Some of the most used third party plugins are VirtueMart (product, custom), JomSocial (community), K2 (fields), Dynamic404 Match Lookups, SimpleLists Link, and MageBridge Product Sales Action and so on.

There are a couple of events that you need to know such as user-plugins events. Every time a user logs in or logs out, Joomla creates an event onUserLogin, onUserLogout, onUserAuthenticate, onUserLoginFailure, onUserBeforeSave/ OnUserAfterSave and OnUserBeforeDelete/ onUserAfterDelete.

You can create plugins which can hook at one or more events and you can do something useful with it.

Joomla comes up with a system of dividing these events to groups so you have a perfect set of events and of features. So you can create an authentication plugin with user authenticate event. These events will be called only when Joomla knows about your newly created plugin so all the events and methods can be used only then.

For example, when Joomla starts to do something regarding the user, all the user plugins are initialized. Also, when Joomla starts to authenticate users, only then the plugin groups authenticate because only. The same comes for all core plugins, excepting the system one.

The system events are always called. It has to do basically with how Joomla works and how Joomla application is initialized.  Joomla is initializing itself making a connection to the database, it is making sure cache is available, it is making sure that basically Joomla is Joomla. And then calls up for system-plugin events such as onAfterInitialise. And at this point, all the system plugins are initialized.

So if you have a system plugin that is activated in the plugin manager, it will automatically start. Also, if a system plugin uses methods to another plugin group such as user, automatically will start. So system plugins always initialize first, having priority. A system plugin can have any methods and function that it is out there. For example, there are multiple system-plugins events: onAfterInitialise, onAfterRoute, onAfterDispatch, onBeforeRender/ onAfterRender, onBeforeCompileHead.

The difficult part about plugins is that you have to choose the proper plugin groups and from different plugin events. So if you want to create a Joomla plugin you also need to know Joomla architecture.

How to Develop Joomla Plugins?

There are multiple reasons for a custom plugin such as modifying HTML code, tweaking document headers, extending a user form, extra authentication-type and a lot more.

We need to define a plugin. A plugin is nothing more than a couple of files in a folder. For example, if we take the system plugin. It has the system folder with another folder in it named an example. This folder has the files example.php, example.xml and index.html. The system plugin also has language files located in administrator/languages/en-GB named en-GB.plg_system_example.ini and en-GB.plg_system_example.sys.ini.

After you created the files, you can go to the Joomla plugin manager and hit discover button and suddenly you will discover your new plugin.

The language file can contain something similar and simple like this:

PLG_SYSTEM_EXAMPLE=”System – Example”

PLG_SYSTEM_EXAMPLE_DESC=”An example System Plugin”

If you want to write a description of your plugin for the plugin manager, you need to write it on the .sys.ini file. Once you open your plugin from the plugin manager the second language file is also used. The .ini language file is meant for a specific situation where the plugin is loaded, but it is not causing so much trouble and overhead for the other plugins.

So a plugin title or description should be in the .sys.ini but also you should copy them to the .ini file too. It is a good idea, to use the .ini file in case you have parameters. Also, if the plugin is doing something to the front end you need to use the .ini file. So in the .sys.ini you should use only two lines: title and description while the other parts of the code you need to write them to the .ini file.

If you are familiar to build your own templates or building a component or other extension, you definitely know to make the XML file. This file contains all the data Joomla needs to install your plugin.

An example is this XML-manifest :

<?xml version=”1.0” encoding=”utf-8”?>
<extension version=”3.0” type=”plugin” group=”system”>
<name> PLG_SYSTEM_EXAMPLE</name>
<filename plugin=”example”>example.php</filename>
<language tag=”en-GB named en-GB.plg_system_example.ini”> </language>
<language tag=”en-GB.plg_system_example.sys.ini” > </language>

So basically, this is the definition file for your extension where it is defined the type of the extension, the group, the version, the name and the description of the plugin. Also, it points to the proper files and language files.

The PHP code it is more interesting and you can write it down in the example.php file. This is the problem-solving part which should start with a file with a class.

So there is an HTML code that needs to change before Joomla sends the output to the browser. So you use the onAfterRender event. Also, you should use a specific Joomla call to the body that actually is a string. You can to some stuff with it and when you are done you can send it back to the HTML code to Joomla. And once Joomla says that is ready to send this body to the client, it is actually modified by this system plugin. What comes between, it all your work and imagination. You could use third party parses, expressions and so on. For example:

Defined (‘_JEXEC’) or die();
jimport( ‘joomla.plugin.plugin’ )’
class plgSystemExample extends JPlugin
Public function onAfterRender()
$body = JResponse::getBody();
// @todo code: Do something with the $body

Now, you just created a nice plugin for Joomla. For more advanced knowledge you need to learn PHP and Joomla from scratch.

Whatever you are just starting out with Joomla or looking for a good and reliable hosting provider for your existing Joomla website, we highly recommend InMotion hosting. They offer a wide range of hosting service to start and grow your website.

Best Joomla Web Hosting

Create and host your Joomla website with InMotion and get a free domain, top notch Joomla support and reliable web hosting service optimized for Joomla.


David Cross

David is the chief editor at WebHostingMedia right from the beginning. He has a great passion for building and managing websites and creating helpful content. He is also interested in programming - currently learning python.