Learn WordPress plugin Development

Dec 12, 2015

Alphanso Tech

Php

1

Learn WordPress plugin Development

A plug-in is a small program, or combination of programs, that sits on top of your WordPress installation and increases the functionality of your website in some way.Plugins are ways to extend and add to the functionality that already exists in WordPress.

WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress.

In simple term, A plugin is group of php,css and javascript files which targets to a certain operations.There are many wordpress plugins available in wordpress official site, A vast community of wordpress plugin development.

Needs of custom plugin development

There are lots of important plugins available in this site such contact form, sliders,image gallery,pagination etc.. but if there is any requirement to add some other functionality to wordpress ,you may not find the plugin,In that case you need to write your own plugin based on your site specification.

This will teach and guide you to  learn WordPress plugin development with step by step guide.

To learn WordPress plugin development you should familiar with HTML,CSS,JavaScript and the most importantly PHP and MySql(To perform Data Driven operation).

In learn WordPress plugin development we will cover up following topics:

  • Where the plugins exist in wordpress directory?
  • Write your first static plugin.
  • Write a dynamic plugin.
  • Auto-Created database while the plugin will be activated.
  • Short Code creation.
  • A simple Insert Update and Delete exercise.

To learn WordPress plugin development ,you need to download and install wordpress first.

The plugins are situated in  XYZwpwp-contentpluginsalphansotech_plugin.

Write your first static plugin :

    • Create a folder i.e alphansotech_plugin at plugin directory,shown as above.
    • create a base file named alphansotech_plugin.php in this folder.
No plugin Display Image

No plugin Display

You can see in the above image, alphansotech_plugin does not display.

write following text into this file,you will see your plugin at wordpress admin panel.

Display your custom plugin

Display your custom plugin

After plugin activation ,we need to create menu which will display to admin panel ,so that we can easily navigate to our plugin from admin panel.For that create some static html files and call these files from this page.Let’s see the example below.

WordPress calls a function and the function renders the html output so it is better to write html code within the function.

create a fine named employee_list.php

WordPress Hooks

WordPress hooks are, essentially, triggers of sorts that allow users to, with short snippets of code, modify areas a WordPress theme or plugin, or add their own code to various parts of WordPress without modifying the original files.

we are using action hooks here.

Action Hooks

Action hooks allow you to execute your custom functions which are referred to as actions.Action hooks allow you to add additional code to the WordPress core or theme so that you can achieve some new functionality or customizations.

we are using add_action(‘tag’,’function_call’) here, it hooks a function on to a specific action.The first argument is the tag (to which you’ll be adding the action), and the second argument specifies the function to call (i.e. your callback).

create a file named employee_list.php

 

Add following code to alphansotech_plugin.php file.

Now, refresh your wordpress and activate your plugin,you will get your menu to the admin panel.

Active wordpress plugin

Active wordpress plugin

When you click on this link,you will get the errors ,because employee_list() function and we have not included the file where the function situated.

Add following code at bottom of  alphansotech_plugin.php file.

Refresh wordpress and click on the Employee Listing Menu,You will get the listing of employees.

Employee Listing

Employee Listing

Above plugin works as static plugin , we didn’t interact with database.Let’s make it dynamic.

The Employee list is static ,now,we will make them dynamic.

First,basic way is create a sql file of data table and import it in wordpress database and then write your code.

Create table

Now,replace following code in employee_list.php

Refresh the page,the data comes is now dynamic,come from database.

While, we download any plugin and active , it create database table automatically, A user does not need to import table manually.So our plugin should have automatic data table creation functionality.

To enable this functionality, we need to write some code in root php file (alphanso_plugin.php )

ShortCode :

A shortcode is a WordPress-specific code that lets you do nifty things with very little effort. Shortcodes can embed files or create objects that would normally require lots of complicated, ugly code in just one line.In simple terminology shortcode is a shortcut to display any file output.

To create shortcode write following function

add_shortcode(‘short code name’, ‘function name’);

add code to employee_list.php at bottom of the page out side the function.

In wordpress write short code name ( [short_employee_list] ) to any page where you want to display employee listing.I have put it in sample page.

shortcode

shortcode

Download the complete source code
For custom web app development services contactus

 

I hope you will find this post very useful regarding WordPress Plugin Development. Let me know any questions if you have in comment regarding WordPress. I will reply you ASAP.

Have you got cool idea about Web Application development or WordPress Development? Contact us Now to get free consultation on your idea. Alphanso Tech is rated as one of the best WordPress  Development Company in India.

 

Post by Alphanso Tech

Created in 2009, Alphanso Tech is a leading IT Consulting company with a presence in the USA, Canada, and India.We are a trusted and leading service provider to many top-tier companies in the area of Custom WordPress Development , Web Application Development , iOS App Development , Outsourcing Services, Online Marketing and many other related activities.

One Response to Learn WordPress plugin Development

Leave a Reply

Your email address will not be published. Required fields are marked *