Hello friends ,
At present to make a plugin is become a very nice activity in WordPress,because all wordpress developers wants different requirements in their different Projecs.So i will explain you only 4 simple steps to make any plugin in WordPress.
Step 1.Folder Hierarchy :-
- In the first step you will have to make a folder of your plugin name in the wordpress -> wp-content -> plugins directory.
- Now in this folder you are going to put your another folder of your coding files,css,js,images and one new plugin file (your_pluginname.php).
- Now you have to write all further step’s code in your_pluginname.php named file.
Step 2. Plugin Activation and Deactivation Concept:-
- In the Plugin File you are going to put your plugin name,your website name,your plugin version and your plugin website name as well as the code of functions like plugin activation,plugin deactivation and its shortcode.
- In Plugin file first of all we have to put plugin configuration code.
Plugin Name: Your Plugin Name
Plugin URI: Your Plugin Site (if any)
Description:Your Plugin working or functionality
Author: Your Name
Version: Your Plugin Version
Author URI: Your Website (if any)
- Now you can see your plugin (without any functionality) in the Dashboard Panel -> Plugins directory.
- In the second step you will have to put your functionality in your_pluginname.php file.
- We have register_activation_hook() function to activate all your functionality of your plugin when plugin is activated.
- In this function the second parameter install is the function in which you are going to implement wordpress database table creation query required for your plugin functionality.If your install function is in the same file than you have to write a __FILE__ in first parameter otherwise you have to give a source path of that file.
Your Database Table Cretion Query
- Now we have another function register_deactivation_hook() which will remove all your functionality. You can also delete any wordpress database table which is not required after deactivate your plugin.
Your Database Table Deletion Query
Step 3. ShortCode Creation for your plugin:-
- Shortcode is the heart concept for any wordpress plugin.It is necessary to make a shortcode for your plugin to put your plugin on any page to display it in GUI.
- It is very simple 3-step process to make a shortcode for your plugin.
1) function shortcode()
Your Plugin Functionality Code
2) function register_shortcodes()
add_shortcode('Your Plugin Shortcode name','shortcode');
- In the first step shortcode is the function which includes all the coding implementation lines which will run wherever you put the shortcode.
- In the second step you have to register your shortcode by the register_shortcodes function in which you can keep any name of the shortcode as the first parameter of the add_shortcode function.
- The third and last step includes the function add_action() which will initializes the action of the register_shortcode function.
- Now we will see some rules for keeping Shortcode name :-
1)Names should be all lowercase and use all letters;
2)Numbers and underscores should work fine too(not dashes)
Step 4.Create an Admin Panel Option For Your Plugin:-
- Admin panel is another nice concept for any wordpress plugin.
- It includes all the customization optins which you will provide for your plugin.
- It is very simple 3-step process to make a Admin Panel for your plugin.
1) add_action('admin_menu', 'my_first_admin_menu');
2) function my_first_admin_menu()
add_menu_page('Plugin Admin Options', 'Your Plugin Admin Panel Name', 'manage_options','my first','admin_panel);
3) function admin_panel()
Code For Your Admin Panel Options
- Now you can see one option is added to your wordpress dashboard admin panel.
- In the first stepthe action is added to the dashboard panel to create a new menu (panel).
- In the second option you have to give any name to your Admin Panel option which will incude in the dashboard panel option of wordpress.add_menu_page function will create a admin page for your customizing options.
- In the third and last step you have to create a function which named as in the last parameter of the function add_menu _page and it will includes the coding impletion lines for customizing the plugin functionalities.
This is the very simple four steps and now you can create your own plugin .Enjoy..