Jump to content

WordPress Plugin Development Tutorial

0
  j.mike's Photo
Posted Nov 05 2012 04:31 AM

In this era of open source software communities, everyone has the freedom of creating tailor made web application for making a website’s user interface impactful. Additionally, you can also develop object oriented Plugins for enhancing the functionality and workability of your website. Today, you can find top five leading open source communities that are satisfying the objects of a large volume of website. Such open source communities are wordpress, Drupal, Joomla, Mybb, and Magento. Among these communities, WordPress is known for creating growth friendly Plugins. Wordpress is the open source project, which is being written in PHP. Thus, you can create the WP Plugins, if you have the understanding of wordpress. With wordpress, you can create new WP Plugins as well as modify the existing ones for increasing the needed functionality in your website. For doing so, you can hire Wordpress developers who can make use of WordPress Plugin API.

Although, you can find the WP plugin of your use over web, but this article can enhance your knowledge and make you able to develop the needed custom wordpress Plugins.

Explore the WordPress: In your process of creating custom wordpress plugins, you need to make yourself familiar with WordPress environment at first. It will develop an understanding of organization, arrangement, and referencing method of wordpress interface. As it is also mentioned above that the understanding with PHP is must for going further.

wp-content/plugins
Further, you need to create a folder for storing up your custom Plugin. In this folder, you will write your PHP and Javascript codes. Moreover, this folder will also accommodate CSS and images that render the codes to make the WP plugin user-friendly.

Add Header Code in Your Plugin: Once, you get done with Folder creation. You can proceed to the next step of creating a PHP file in your folder and naming it as “c.php”. Further, you can add the below given code in your PHP file.

<?php
/*
Plugin Name: Author
Plugin URI: http://www.davgit.com
Version: 1.0
Description: A Plugin that displays author info for each post.
Author: David Gitonga
Author UI: http://www.davgit.com
*/


You will have the need to update the above mentioned header information. As it as a standard format that helps WP in recognizing your developed plugin. This plugin info will be shown on the installed Plugin page.

Now Make Your Plugin Functional: For adding the functionality in your website, you need to enter the PHP codes in your Plugin files. For example, we can add one function for accommodating information related to author. Further, you can also use HTML and WP pre-written tags for building author info sections.

Let’s define the below given function

function author_info()
{
?>


Just add the page building HTML codes that are mentioned below:

 <div class = “author_info”>

<?php

if (function_exists (‘get_avatar’))
{
echo get_avatar(get_author_email(), ‘70’);
}
?>

<?php author_meta (‘description’); ?>

</div>

<?php


Note: In this way, it is crucial to know that the template tags convey their functionality.

Take an example: if you will use the “get_author_email” tag, it will bring the author email from profile page of author.

Now you can add the CSS styles by adding the below given codes for controlling the appearance of HTML pages:

<?php
function stylesheet()
{
echo"
<style>
.avatar
{
float:left;background-color: #9A9B9B;padding: 4px;margin: 0 4px 0 0;display: inline;
}
.author_info
{
color: #666;background: #DDDDDD;padding: 8px;margin:0 0 6px 0;
}
</style>
";
} 


Moreover, the CSS styles can be added by developing a separate file named as “styles.css”. Further, you can add the above written in this CSS file.

Load the function that will be executed when the plugin loads below:

function display_author_info()
{
if (is_single())
return author_info().stylesheet();
}


You can also create a file named as “single.php” and make addition of below given code:

<?php
If (function_exists (display_author_info))
Echo
Display_author_info;
?>


Apart from this, you can also impart an optional function called “hook”. It notifies WordPress at the plugin loading time. In your case, you wanted to exhibit the author information right after the post content and before the comments section. Thus, we can add the below given in our “customplugin.php” file:

Add_filter (‘comments_template’, ‘display_author_info’);
?>


Congratulation, you have developed a custom WP application

About the Author: Chris Miller is a PHP developers (expert magento developers) for a leading PHP Development Company. He writes concrete information on php frameworks tutorials on CMS solutions.

0 Replies