How to Develop a Joomla 1.5 Plugin

As we know, the plugin structure of Joomla (I’m talking about Joomla 1.5) is understandable, powerful and flexible. Joomla plugins are not only used for triggering events by extensions and core applications, it can be used as an extensible and powerful extension.

How to Install Joomla Plugin

Joomla plugins can be installed by uploading it (plugin should be in .zip or .tar.gz file format). Installation process is managed by a XML file. Ignore any <p> and <br> tag in the code. Basic structure of the XML file is:

[code type=”xml”]

<?xml version=”1.0″ encoding=”iso-8859-1″?>
<install version=”1.5″ type=”plugin” group=”*****”>
<name>Name of Plugin</name>
<author>Author Name</author>
<creationDate>Date of Creation</creationDate>
<copyright>Copyright Information</copyright>
<license>GNU/GPL</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.yoursite.com</authorUrl>
<description>Plugin Description</description>
<files>
<filename plugin=”categories.searchbot”>categories.searchbot.php</filename>
</files>
<params>
<param name=”search_limit” type=”text” size=”5″ default=”50″ label=”Search Limit” description=”Number of search items to return”/>
</params>
</install>

[/code]

As you can see, we are using <install> similar to Joomla XML installation file. group=”*****” specifies the name currently existing plugin for the new eveyy type you argument for example, group=”user” or group=”authentication”. type=”plugin” specifies we are installing a plugin. <filename tells Joomla where to add the plugin files. <params> is used for extended functionality for displaying in plugin admin section.

When we are developing the plugins we define a subclass under JPlugin. Below is the example code snipet:

[code type=”php”]

<?php
// Restrict Direct Access
defined( ‘_JEXEC’ ) or die( ‘Restricted access’ );

// Importing library dependencies
jimport(‘joomla.plugin.plugin’);

class plg<PluginGroupName><PluginName> extends JPlugin
{
// Constructor
function plg<PluginGroup><PluginName>( &$subject, $config )
{
parent::__construct( $subject, $config );

}
/**
* Plugin method with the same name as the event will be called automatically.
*/
function <EventName>()
{
$app = &JFactory::getApplication();

// Plugin code goes here.
// You can access parameters via $this->params.
return true;
}
}
?>

[/code]

How to call plugins in your code

If your plugin is utilizing Joomla built-in events, then you don’t have to add code in your theme files. Keep in mind that the parameters should be in an array. But if you want to trigger an event, then you can use following code like code

[code type=”codetype”]

$dispatcher =& JDispatcher::getInstance();
$results = $dispatcher->trigger( ‘<EventName>’, <ParameterArray> );

[/code]

Duan Lingxin

Duan Lingxin

Content crafter and chief editor at Scratching Info. Also regular contributor on other major online tech platforms. Security Specialist by day and a writer by night, he does his best to instill his knowledge about tech while delivering inspiring and life changing resources through his writing,

More Posts - Website

Leave a Comment