How-to-Create-Wordpress-plugin hotchpotchpost
How to Create Wordpress Plugin

First, you need to create your basic files and folder structure. WordPress stores its plugins in the wp-content/plugins/ folder. This is the place where you’ll be adding your files as well. Normally, if your plugin is going to be very simple, you will include all the code inside one single PHP file. In this case, you will simply store the file in the folder mentioned above. However, for complex case, you may be using more thank one files therefore you’ll be putting all your files in a unique folder that you’ll name, let suppose you named it my_new_plugin. Go ahead and create this folder.

Next, you must create your main plugin file. Let’s suppose you name it my_new_plugin.php. You can really name it whatever you want, it doesn’t make any difference.

If you now open your WordPress administration panel and navigate to the Plugins sections, you will see nothing changed yet.

It’s time to change that and tell WordPress that our file is going to implement a plugin. The process to do so is very simple. All you need to do is add a plugin specific information header to your newly created file. This standard header can be written like this:



Plugin Name: My New Plugin

Plugin URI: Enter url of you plugin.

Description: My plugin description

Author: Your name

Version: version number

Author URI: Your contact information url



Simple enough, don’t you think? You can, of course, change the content of this header to your liking but make sure you keep all the lines, otherwise WordPress won’t correctly recognize your plugin.
If you refresh your administration panel’s plugin page, you’ll now see our plugin listed along with the other ones.
See how all the relevant information like name, description, author, URL are extracted from the information header? This is why it is always important to correctly fill out this information. Let’s go and activate your plugin by clicking Activate to the right of the plugin entry.
Your plugin is now shown in the administration panel so WordPress is aware of it. However, it doesn’t do anything as it contains nothing except of the information header. You are going to change this now.

WordPress offers a great way to include your plugin code in different places all over the template, be it physical positions within a page or logical positions within the process of building up a page that is going to be displayed. First, you are going to have a closer look at the second category, the logical positions, better known as action hooks.

Action Hooks for plugin

You can view action hooks as callback function. Whenever WordPress is executing a certain operation, like, for instance, displaying any page for example page footer, it will allow your plugins to execute their own code that must be run at that exact moment.

For a better understanding, let’s consider a generic plugin called my_plugin that implements a function called when_footer_displayed() that has to be run whenever the page footer is displayed. You will tell WordPress to call this function, at the moment of displaying the footer by using a special function called add_action():

<php add_action(‘wp_footer’, ‘when_footer_displayed’); ?>

The add_action() function takes the action hook name as its first parameter and the name of the function that must be executed, as a second parameter. This function call will be added to your main plugin file (the one containing the information header), usually, right under the function code that needs to be executed (when_footer_displayed() in our example). You will find the full list of available action hooks in the WordPress Codex.

Next you’ll be using action hooks , where you are going to build the administration page for your plugin.

Continue to Next Step



Comments Protected by WP-SpamShield Spam Blocker