Writing your own WordPress plugin is not that difficult if you are a web developer with basic PHP skills. The only thing you will need, coupled with your PHP skills, is some direction, some resources, a little information on how WordPress expects your plugin to behave and, most importantly, a great idea.
If you are a newbie, don’t be put off or daunted by all the code, ultimately a plugin is only a program, a set of functions, that adds a specific set of features and services that can be executed in different sections of your WordPress site.
This article covers WordPress Plugin Development, from tutorials, useful resources, how-tos, guides, and some cheat sheets.
WP Plugin Information Header
The top of your Plugin's main PHP file must contain a standard Plugin information header. This header lets WordPress recognize that your Plugin exists, adds it to the Plugin management screen so it can be activated, load it, and run its functions. This is the code:
<?PHP /* Plugin Name: Name Of The Plugin Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates Description: A brief description of the Plugin. Version: The Plugin's Version Number, e.g.: 1.0 Author: Name Of The Plugin Author Author URI: http://URI_Of_The_Plugin_Author */ ?>
Following the header it is now time for the licence, which is optional, you don't have to do it. It is good practice to do so, though. Here is the code:
<?php /* Copyright YEAR PLUGIN_AUTHOR_NAME (email : PLUGIN AUTHOR EMAIL) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ?>
Filter and Action Hooks and Template Tags
Plugins function simply by connecting to one or more "hooks", they could be either "filter" or "action" hooks, and work by modifying the default behavior of WordPress.
Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. View the Wordpess Action Hook List here: WP Actions Reference.
Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. View the WordPress Filter Hook List here: WP Filter Reference.
Another way to add functionality to a plugin is by creating custom Template Tags. Someone who wants to use your Plugin can add these "tags" to their theme, in the sidebar, post content section, or wherever it is appropriate. For a detailed look at WP template tags click here: Template Tags List.
WordPress Hooks Database
If you're a plugin developer, you will know how difficult it can be to figure out which hooks are available. This WordPress hooks database automatically scans each WP build for apply_filters(), do_action(), and do_action_ref_array to figure out exactly which hooks are available in each version and where the hooks occur. An invaluable resource.
You can filter the hooks by version and view new hooks, as well as viewing deleted hooks.
This video tutorial, from WordPress TV, demonstrates the basics of constructing a plugin, designing it to make the changes you want, and then using that plugin to alter your WordPress site in a persistent way. Includes some basic discussion on hooks and functions, as well as some sample code.
WordPress Plugin Development – Video
A small and basic tutorial on how to develop a WordPress plugin.
A widget is a PHP function that echoes string data to STDOUT when called. To turn such a PHP function into a WordPress Widget, it must be registered as such. This is done using a PHP callback (a Pseudo-Type in PHP documentation) that is registered by a WordPress widget API function.
With the release of WordPress 2.7, a new Dashboard Widgets API was introduced that makes it very simple to add new widgets to the administration dashboard. Doing so requires working knowledge of PHP and the WordPress Plugin API, but to plugin or theme authors familiar with hooking actions and filters it only takes a few minutes and can be a great way to make your plugin even more useful.
This resource contains the technical documentation of the WordPress Widgets API: Widgets API
How to Write a WordPress Plugin – Devlounge
Whereas the above plugin overview and tutorial will help you with the basics and help you with your first steps within plugin development, this extensive tutorial by Ronald Huereca, will get your hands dirty and guide you towards developing a powerful and multi-functional plugin. This tutorial is for the advanced user.
How to Write a WordPress Plugin is an extensive and in-depth, twelve entry series on the process of creating your own WordPress plugin. Every step is covered, from “Seven Steps for Writing a WordPress Plugin” all the way down to adding Ajax to your plugin and releasing it.
Table of Contents: How to Write a WordPress Plugin
- How to Write a WordPress Plugin – Introduction
- Seven Reasons to Write a WordPress Plugin
- How to Get Ideas for WordPress Plugins
- Structure of a WordPress Plugin
- WordPress Plugin Actions
- WordPress Plugin Filters
- Constructing a WordPress Plugin Admin Panel
- Constructing a WordPress Plugin User’s Panel
- WordPress Plugins and Database Interaction
- Using AJAX with your WordPress Plugin
- Releasing and Promoting Your WordPress Plugin
This tutorial covers information on how WordPress expects your plugin to behave. WordPress is well known for its amazing collection of free plugins. There is one for almost every need you can think of, from backing up your WordPress installation to asking for a cup of coffee or fighting spam. But there are times when none of the available plugins seem to quite do the trick you are looking for. To help you in moments like that, this tutorial will guide you through every step of building a simple, widgetized WordPress plugin with settings.
This extensive tutorial from Net Tuts will teach you how to create a WordPress plugin that extracts and displays products from an external OSCommerce shop database. It will show you the file structure of a plugin and where it will be included in the WordPress structure, then how to make the plugin visible for WordPress and integrate it with actions run by its frame. Next, creating the configuration panel and then how to implement the front-end functions themselves that will interact with the OSCommerce database and extract the required data.
The great thing about WordPress is that it's highly customizable and flexible. Within a WordPress plugin, almost all of the fields could be changed to your desired results. When you are building a WordPress Plugin, chances are there is a need for you to create some admin pages for the users to customize the setting they want.
WordPress admin default has their own CSS style, and you can make use of it for your WordPress Plugin Admin Panel if you require one. If you require additional styling for your admin panel, you can also link in an external CSS stylesheet within your plugin.