How to create a wordpress plugin

In this tutorial, I'll teach you how to create a wordpress plugin. I'll create simple plugin for beginners point of view. Let's say our plugin name is acronym. The working of this plugin will be to display image instead of text.

So, to begin this development, you'll need a code editor like Dreamweaver. Please keep in mind that if you want to create any plugin, every time you'll have to document your plugin, so that your plugin could show on the plugin admin page. Place the following document registering code into the top of plugin file. Here is the code:


<?php
/*
Plugin Name: Display Image instead of text
URL: your website url or any url that you want to put
Description: any description you want to display
Author: author name
Version: version
*/
?>
Wordpress plugin works with the wordpress plugin hooks. Detail information about plugin hooks are available on wordpress. Their are two types of hooks in plugin development, one is "Actions" and other is "Filters"

Actions hook triggers when a specific wordpress actions happens, for example, when a new post is published. So wordpress do only one thing, it tells the plugin that this action happen and moves to other tasks.

In filters, wordpress observes that your plugin is processing the some data and returning back to the wordpress. For example, in our plugin, Wordpress will shift post text to your plugin, plugin will process the coming text and will return back to the wordpress, so that wordpress will display will display the processed text.

So, that's what we want, we will call post text using wordpress into our plugin and will process the text and convert to the image and will pass to the wordpress for displaying our processed code result. So, we'll use the 'the_content' filter.

After your plugin document code as mentioned above, put the following code in the file.

<?php
add_filter('the_content', 'acronym_content');
function acronym_content($content) {
return $content; }
?>
So, every time wordpress will publish a post, the content of post will connect to our function acronym_content. This process in wordpress world is called 'registering a plugin sink'.

You can see the clear acronym_content() operate, too. The operate acronym_content() is a mess up for the "the_content" connect. I discuss this just so that we all know what we're discussing.

Observe that this plugin code will now run, although it doesn't actually do any handling. Just publish it to your plug-ins index (/wp-content/plugins) and stimulate it in your WordPress administration system.

Well, now all we need to do is modify the publish articles so that the textual articles we're looking for is covered with a unique "popup" tag.

$acronym = array('abcde' => 'http://www.anytingyouwant.com/images/abcde.jpg');
  So we have the record, now we need to secure the record products when they appear in the publish articles. This is very simple to do with one of the built-in PHP substitute features and a little array range adjustment.

function acronym_content($content)
{
global $acronym;
$strings_search = array_keys($acronym);
$modify_strings = array_values($acronym);
$strings_search = array_map('acronym_search', $strings_search);
$modify_strings = array_map('acronym_replace', $modify_strings);
$content = preg_replace($stings_search, $modify_strings, $content);
return $content;
}

So, that is your plugin ready to use.

2 comments:

  1. Great information for wordpress plugin creative ideas.

    ReplyDelete
  2. Thanks for this useful post. For more visit: examanswer24.com

    ReplyDelete