Writing your own Wordpress Plugin

by lechu on September 30, 2008

image Wordpress plugin is an addon for Wordpress blogs to add new features to the blog. There are tons of Wordpress extensions available at the Wordpress extension directory. I recently wrote a twitter extension for Wordpress which is available for public download here.

 

If you are planing to write your own Wordpress extension, you can do it if you have knowledge of PHP and if you are aware of the Wordpress functionality.

For writing a Wordpress plugin you need to first create a file with the following code on top part of the file. You need to maintain the coding style of the Wordpress plugin as per the Wordpress Documentation

<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the plugin.
Version: The plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
*/
?>

The licence part of a Wordpress plugin

<?php
/*  Copyright YEAR  PLUGIN_AUTHOR_NAME  (email : PLUGIN AUTHOR EMAIL)
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
?>

The above two codes are the standard for Wordpress plugins and you need to follow that

Then comes the programing part of the wordpress. I show a simple function which prints some text

<?php
function myFirstPlugin($mycontent) {
    return str_replace("kishore", "<a href = \"http://kish.in\">Kishore</a>");
}
?>
<?php add_filter('the_content','myFirstPlugin'); ?>

Your first plugin is ready for testing.

What does this plugin do?

I have created a function which replaces the text, “Kishore” with a link to my blog. I have used the filter “the_content” which replaces the text of the content of post.

Possibly Interesting Posts

New Guidelines for Plugin Developers - Wordpress : Mark Jaquith has written on his blog on the Wordpress plugin repository where Plugin Authors can hos..[](0)
Adobe Plugs 13 Security Holes in Critical Update : Adobe Systems embarks on a new schedule for security updates with 13 critical fixes in tow for Reade..[](1)
Security Expert Suggests Twitter Focus on Output Escaping not Input Filtering : Twitter's status blog this morning announced that Twitter has addressed the most recent variant of..[](1)
iPhone Upgrade 3.01 - SMS Vulnerability Fix : You have to update your iPhone with version 3.01. This fixes an SMS vulnerability.The flaw, disclos..[](23)
Fill out your e-mail address to receive our free newsletter from Kishore Blog!
E-mail address:
Name:
 

{ 1 trackback }

Checklist for submitting your plugin to Wordpress Extension Directory | Technology Blog
September 30, 2008 at 5:46 pm

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: