Page 1

WordPress Plugin Development

www.headwaywebsolutions.com


WordPress is a free CMS (Content Management System) and open source blogging tool; it has totally changed the look on the internet, whether we are talking about software or website development.

Now in this part we will be discussing how to create a wordpress plugin with our simple but effective steps. Now when we talk about plugins, then most probably the non tech guys will think of a complex function, followed by the knowledge of lot of tech languages which is just a myth and this is what we will show here, that how easy it is to create a Wordpress plugin, all you need to know is a bit of PHP and a basic understanding of WP file structure and Admin panel.

www.headwaywebsolutions.com


Now before starting up with how to create a WP plugin, I would first like to discuss why to develop a wordpress plugin. ď ˝

Why to have a WordPress plugin?

In simple words if we want to define plugins, then we can say that these are same as addons added to your browser for making certain things simpler for you. ď ˝

Example: All in one SEO plugin from Wordpress is a plugin that help you in optimizing your site and making it search engine friendly with it simple but effective features at a single place, some of the features provided by. All in one SEO plugin are:

www.headwaywebsolutions.com


    

 

Google Analytics support Support for Custom Post Types Advanced Canonical URLs Fine tune Page Navigational Links Built-in API so other plugins/themes can access and extend functionality ONLY plugin to provide SEO Integration for WP e-Commerce sites Nonce Security

this is what a simple Plugin can offer you. And developing a pluging will give you a better understanding as how things work at the backend and another benefit is that being a developer you can have a complete control over the function of your plugin.

www.headwaywebsolutions.com


Steps of developing a WP plugin:

www.headwaywebsolutions.com


1. WP Folder Structure

The wordpress folder structure will show you the basic application directory within wordpress, in here you will find a Plugin directory where you can find all the plugins installed,

For smaller plug-ins which only requires a single .php file, you can place them directly into the plug-ins/ directory. But when you start creating more complex applications, it is a better option to create a sub directory named after your plug-in where you can assemble all JavaScript, CSS, and HTML along with the PHP functions.

www.headwaywebsolutions.com


Figure 1

www.headwaywebsolutions.com


Figure 2

www.headwaywebsolutions.com


ď ˝

And if you want to provide your plugin to others for download, so that others to get benefited from it, then these are the simple things that you need to keep in mind before providing a readme.txt file, this file should contain your name and functionality of the plugin and further if you want, that people should know about the updates in the plugins then you should provide details about each revision.

www.headwaywebsolutions.com


2. Starting Your PHP File

Start with a simple PHP file while creating a new plugin. This should be your plug-in’s official name. For example I have created base code and have named the file quick-subscribe-now.php.

The first lines of your plug-in must be comment. This is extremely important as WordPress will be unable to process your file without it. Below is an example code snippit you can copy and mold towards your own.


www.headwaywebsolutions.com


3. WordPress Naming Conventions And Best Practices

ď ˝

While writing code it’s best to follow regulations and guides set up by WordPress. Since there are so many functions defined already, you can avoid duplicity by providing prefix label to all your variables and function names.

www.headwaywebsolutions.com


  

  

<?php function Subscribe_Widget() { $widget_ops = array( 'classname' => 'subscribe', 'description' => __('An example widget that displays a quick subscribe now form.', 'subscribe') ); $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'subscribe-widget' ); $this->WP_Widget( 'subscribe-widget', __('Subscribe Widget', 'subscribe'), $widget_ops, $control_ops ); }// the code } ?>

In the above examples we prefixed all our setting names with quicksubscribe-now. This can be replaced with any keyword of your choosing usually related to your plugin name.

www.headwaywebsolutions.com


4. Filters and Actions 

Filters and actions are two completely different concepts which relate deeply in the ways they manipulate plugin data.

Understanding Add_filter() A filter is used on a bit of text or data being passed into WordPress. With filters you are quite literally able to filter content through your own custom written functions to change data in any way. 

Understanding Add_action() Actions are similar to filters in that they don’t work on bits of data but instead target pre-defined areas in your templates and admin panel. 

www.headwaywebsolutions.com


Example you can apply an action whenever you update or edit a page’s content. A small list of example actions:

publish_post – called when a post is published or when status is changed into “published”

wp_head – called when the template is loaded and runs the wp_head() function

trackback_post – called whenever a new trackback is added into a post

www.headwaywebsolutions.com


Installing And Running The Plugin 

I’ve created a sample file for the plugin to demo if you’d like to skip the hard coding. Simply download this file (rename it to .php) or copy/paste the code into a new PHP document and upload this to your /wp-content/plugins directory.

www.headwaywebsolutions.com


www.headwaywebsolutions.com


Once completed youâ&#x20AC;&#x2122;ll want to access the WordPress administration panel and browse your current set of plug-ins for the demo just installed. Once you activate nothing new will happen, not until we manually add in our function call. To do this simply navigates Appearance -> Editor and look forsingle.php.

This file contains the entire template HTML/CSS for your basic article post page. Scroll down until you find the_content() and replace with the example code above. This will limit all your article pages to 55 characters no matter what view is being used. You could also add in this function to similar pages in your templates directory such as search.php or archive.php.

www.headwaywebsolutions.com


Thanks You for your valuable time, for more information feel free to contact us on www.headwaywebsolutions.com

www.headwaywebsolutions.com

Wordpress development  
Advertisement