What is WordPress Plugin: Most of you are aware about what is actually a wordpress plugin, what is their use and how it plays a very vital role when you are developing any kind of wordpress website.
But for those who are not aware about this I tell you a wordpress plugin is a piece of software containing a group of functions that can be added to a WordPress website.
So, in last blog we understand what is actions and filters you can say plugin is the extended version of them in terms of adding and modifying the functionality of our wordpress website and if the plugin can do this type of thing then it’s obvious to use the wordpress hooks like actions and filters for creating a plugin if you read my last blog of actions and filters you can easily understand what are the hooks in wordpress.
Basics of Plugin Development: So, now we understand what is actually a plugin and what it’s used for in the wordpress website. Now a question arises how can we develop a plugin , so we have to follow predefined rules of wordpress for starting to develop a plugin . We have to follow some basic steps for that:
- Firstly we have to go to our file manager -> wp-content->plugins this folder is where we are creating our plugin.
- Now we have to create a folder of our plugin. We should name our plugin folder related to its functionality so that if any other person can see our code he or she can understand what the plugin is for by only seeing its name.
- Then after creating the folder our first work to do is create a main plugin file you can say it’s index file. You can name that file whatever you want , you can name index.php or you can just write what you named your plugin with the .php extension.
- After creating that file you have to fill in some important information to the plugin, on the basis of that information wordpress can only understand that you are creating a plugin. This information you have to plugin the main file which is in your plugin folder. So what’s the information here I can give you an example for that, so that you will understand how can we start our plugin development , so write these information in php comments:
<?php
/**
* Plugin Name: My New WP Plugin
* Description: Show how to works plugin in WP
* Version: 1.0
* Author: John
* Author URI: https://xyz.com
*/
So, in the above example of code we can easily see what is the basic code or information a wordpress plugin needed to start the plugin development , I don’t think there is any need to explain what is the meaning of information it can be easily understandable by it’s name.
- After adding this code you can see that wordpress added your plugin into the your admin panel here : wp-admin->Plugins.
- So , now you can see your plugin in admin panel, but the work is not over here, now you have to start the development or we can say plugin coding , you have to think on which purpose you are creating the plugin according to that you have to create the php function first, and you can use the action and filters for and and enhancing the functionality.
So, now we can understand what is the wordpress plugin and how can we start the development for that. It is one of the very useful features of wordpress providing because sometimes we want a particular functionality into the multiple wordpress website so rather creating functionality from scratch you can create that by a plugin and use it in more that or as many wordpress websites you want.Wordpress also has a very good repository of plugins you can name a functionality and search it on the wordpress repository here:
wp-admin->plugins->add new
In the above location you can find a search box over there you can search by the functionality name which is in your mind and you can see the multiple plugins are listed down there you can directly install those plugins from there.
You also search your plugin directly to your browser and you will find multiple suggestions for the plugins.
The Development– So, after once you are done with the starting formalities of your wordpress you can directly write the php code or if you want the special admin section for managing and using your plugin you have to do this by adding menu items or using add_action for that.
Once you have done that you can write your functionality on the call back function which you are using in the add_menu function.
It’s little bit confusing I will explain it to you by the example:
function ut_plugin_top_menu(){
add_menu_page(‘My Plugin’, ‘My Plugin’, ‘manage_options’, __FILE__, ‘clivern_render_plugin_page’, plugins_url(‘/img/icon.png’,__DIR__));
}
add_action(‘admin_menu’,’ut_plugin_top_menu’);
By using the above code you can add a menu item for creating a management panel for your plugin in the wordpress admin panel. For creating the functionality you have to use the call back function for that.
Callback Function- The callback function is which function you already used in the add_menu_page function as a main parameter , this function decides what that particular menu item actually does. In the above example , the ‘clivern_render_plugin_page’ is referred to as the callback function.
In this function you can write what you want to see under that menu item in the admin panel of wordpress.
So, we can see the multiple possibilities in wordpress plugin development, we can add menu and create our own space in the admin panel, we can add new functionality rather than default wordpress provides us, as I told you before hooks are playing very important role in this , and what are the hooks you can refer my hooks blog.