From last few days i have received many request for the simple steps of writing a Joomla Plugin. So, i am back with the simple steps of writing a Joomla Plugin. As we know Joomla is the most popular CMS in these days. So, becoming a Joomla Plugin developer is also a good idea to earn some money (you can even sell it ;) ) Joomla plugins are mostly use to find any string pattern in content dynamically and if a pattern is found then we  replace that pattern with what ever we like.

Ok let’s start it in few simple steps,

Step 1. Create a new XML file and write these lines in the file( you can use any text editor but dreamweaver is recommended ).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="iso-8859-1"?>
<install version="1.5" type="plugin" group="content">
<name>this is testing plugin</name>
<author>Ankur Sharma</author>
<creationDate>16/08/2010</creationDate>
<copyright>Wamptech</copyright>
<authorEmail>ankursharma.niit@gmail.com</authorEmail>
<authorUrl>www.ankursharma.net</authorUrl>
<version>1.0</version>
<description>plugin description here</description>
<params>
<param name="test_title" type="spacer" default="===please enter Options ===" label="" description="" />
<param name="test_opt1" type="text" default="xyz" label="Option 1" description="option 1 for testing" />
<param name="test_opt2" type="text" default="abc" label="Option 2" description=" option 2 for testing" />
</params>
<files>
<filename plugin="test">test.php</filename>
</files>
</install>

Step 2. Write the plugin name in between <name>…</name>

and similarly change author, creation date, copyright, author email,author url, version and description.

Step 3. In between the <filename></filename> write a php file name and create a new php file with the same name.

Step 4. Use the following code for its functional part:-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
 
class plgContenttest extends JPlugin    // class for the plugin, class name format plg+type+pluginname
{
//Constructor
function plgContenttest(&$subject )       //constructor
{
parent::__construct( $subject );   
}
 
function onPrepareContent(&$row, &$params, $limitstart) {         //to be called
 
if ( !preg_match("[texttobefound]", $row->text)  ) {   // return back if [texttobefound] not found in article $row->text
return;
}
 
$plugin =& JPluginHelper::getPlugin('content', 'test');
$pluginParams = new JParameter( $plugin->params ); 
 
// Parameters
$opt1     = $pluginParams->get('test_opt1', 'xyz2');
$opt2        = $pluginParams->get('test_opt2', 'abc');
 
$row->text = str_replace( "[texttobefound]","hi",$row->text);        //replace the content  of article with your value
 
}
}
 
?>

Here we are done.
Now, Zip both the files in one and install it by using the Joomla installer.

One Response so far.

  1. Kairi says:

    I wanted to spend a mntuie to thank you for this.