By Kelsey Jones

Most developers know how to add and install WordPress plugins and even write WordPress themes from scratch, but also learning how to write and develop WordPress plugins can also be an invaluable skill. Many developers release free WordPress plugins to market their own business, while others offer paid plugins to bring in additional residual income.

For whatever reason, any skilled developer with knowledge of PHP can create his or her own WordPress plugin. This tutorial will take you through the basics of WordPress plugin development.

Step One: Make Sure You Have The Most Recent WordPress.org Version Installed on Your Computer.

This tip from Nettuts+ ensures that it is easy to upload your plugin into WordPress once it is finished. Remember, all fields must be filled out in order for the plugin to be recognized in WordPress. This will be discussed in more detail later in the tutorial.

Step Two: Create the Initial Plugin Files

This initial plugin files that need to be created are:

  • PluginName.php, with your Plugin Name as the name of the file (check the plugin directory to make sure your Plugin has a unique and descriptive name.) This file must be in UTF-8 encoding.
  • Readme.txt file if your plugin will be hosted on the WordPress Plugin Directory (The WordPress Codex notes: “Note that the WordPress plugin repository takes the “Requires” and “Tested up to” versions from the readme.txt in the stable tag.”)
  • Plugin Home Page: Create a Word or .TXT file that contains the content for the plugin’s homepage on the Plugin Directory. This page will give a description of the plugin and its main functions, as well as compatibility and any updates as the plugin evolves to later versions.

Here’s an example of a Plugin Home Page for All-In-One SEO Pack:

clip_image002Screenshot Taken 2/14/2012

Step Three: Create the File Headers for the main PluginName.php File

Write the Plugin Information Header. It should follow this format:

clip_image004Coding Example From the WordPress Codex

This is the minimum amount of information needed by WordPress. Line order isn’t important.

The other crucial initial portion of a WordPress plugin is the License section, which should look something like this in order to be compatible with GPL2:

clip_image006
Coding Example From the WordPress Codex

Step Four: Program the Plugin Hooks

Begin filling in the code for the plugin. WordPress plugins work with WordPress by outlining hooks that are set to run a function each time a certain action is completed in the WordPress CMS. Each time an action is completed, WordPress checks for plugins that have applicable hooks, and run their assigned action at that time. This is how plugins modify WordPress and its features.

For instance, if a plugin is set to modify something with the author, the hook would be a “filter” hook called “the_author”.

Here’s an example of a “filter” hook:

clip_image007
Filter Hook Example Taken From Nettuts+

For “action” hooks, a plugin developer can name areas of the WordPress website where the plugin will run. For instance, a plugin could add information in the sidebar by adding an “action” hook called “wp_sidebar”.

Here’s an example of an action hook:

clip_image009

Action Hook Example Taken From WordPress codex

To learn about the available WordPress filters and actions, visit the WordPress Codex Plugin API page.

Step Five: Program the Plugin Functions

Write what the plugin functions are when a filter and/or action hook is triggered by WordPress. This is where PHP and HTML knowledge are needed most. (Graphic from HongKiat.com)

clip_image011Step Six: Adding Administration Menus, Plugin Data Saving, and More

To add additional features, such as administration menus, plugin data saving, WordPress Options Mechanism, and more, check out the bottom half of the WordPress Plugin Overview.

Step Seven: If Applicable, Upload the WordPress Plugin

If you are uploading your plugin for others to use, go into the WordPress Plugin Developer Center to add your plugin. Once you have added your plugin, you can view how many people have downloaded it, user’s comments on the plugin, and the plugin rating. Ratings and comments are also displayed on the Home Page of the Plugin mentioned previously.

To upload a WordPress plugin:

  1. Sign up for a WordPress Plugin developer account and your plugin will be reviewed after you have added it.
  2. Once approved, you will gain access to a subversion repository.
  3. Next, add your plugin and all applicable files (including the readme.txt file).
  4. Finally, your plugin will be added into the Plugins Browser for others to download.

After the plugin has been released and is available for download, be sure to take user’s comments into consideration when adding features or fixing bugs in later versions of your plugins.

Kelsey Jones

Kelsey Jones

Founder/Chief Marketing Consultant at Six Stories
Kelsey Jones helps clients around the world grow their social media, content, and search marketing presence. She enjoys writing and consuming all kinds of content, both in digital and tattered paperback form.
Kelsey Jones
Kelsey Jones