How Do You Write a WordPress Plugin
One of the things that I am most often asked is “How do you write a WordPress plugin?” In this post, I’d like to talk about the process that I go through when I am contracted to write a new plugin. While I won’t delve into the technical details here, I hope this can give you some insight into how I do things, and how you can do things if you’re willing to invest the time and energy to learn how.
1. Gather Requirements
When I’m getting ready to start a plugin project, I always make sure that I have a full and somewhat detailed specification of what my client wants. Going through a requirements gathering period serves to determine three main things.
- Feasibility — It is important to determine if requirements can be met through the development of a plugin. You need to examine the requirements and then, if you’re unfamiliar with the functionality that would need to be introduced, go ahead and examine the WordPress plugin API. Believe it or not, there are some things that you just can’t do within the limits of the API, and you need to know that before you start.
- Scope — One of the largest problems with software development projects is the advent of scope creep. Determining the scope before a project starts involves recording all the functions a plugin must provide. This step usually involves asking your potential client a load of questions to really drill down and understand what they want. The goal is always to get away from a vague project goal and get into the meat of what the plugin needs to do.
- Estimate — There is a big difference between a small plugin project and a large plugin project, both in terms of complexity and time commitment. Determining the scope allows for an accurate quote and completion estimate.
2. Determine Approach
After gathering requirements, I spend some time determining what my approach to the plugin will be. How will I create the functionality required and what is the “best” way to do it? Much of this step will be determined by my prior knowledge or the research I did in step 1. Most plugins require you to add an administration page of some sort, so I became quite familiar with that process almost immediately. After that, it is important to determine what you’re going to do to make things easiest for the end user.
As an example, consider a plugin that adds a small amount of content designed to be shown in or around a single post. This may be for a social bookmark button or something similar. There are several approaches you could take. You could directly modify the post content via a filter, add a template tag that the user would have to put in their template files, or some other method.
As you can see, there are generally a variety of approaches that you can take to accomplish a single goal. You have to determine which is the best for the situation and consider any advantages and drawbacks that come with it.
3. Implementation
If you’ve done the correct amount of preparation in steps 1 and 2, then implementation should be the easiest step so far. You’ll know what you have to do and how you’re going to do it. Now you just have to sit down and write the plumbing code that hooks all the functionality you need into WordPress’s ecosystem.
In general, you’ll have to write activation and deactivation hooks, write a class that encompasses all your functionality, and register action and filter hooks. All this can be time consuming, so you may want to keep around a template file if you plan on writing a lot of plugins. Make sure to follow the WordPress coding standards.
4. Testing
The last and final step in the implementation of any plugin is the testing step. You need to verify that your plugin does what it is supposed to on a variety of platforms and with a number of different inputs. Do you give the user appropriate error messages? Do you validate inputs and make sure that nothing gets through that shouldn’t? Is your plugin PHP4 and PHP5 compatible or does it not matter?
All these are important questions to answer when you’re testing your plugin. A thorough test before release ensures greater uptake by the community and reflects better on your abilities.
5. Release
After all your implementation work is done, you get to release your plugin to the community. Before doing so, make sure you describe your plugin adequately in the standard readme.txt file that WordPress.org requires and that it comes with a license defining the rights the user has. Hopefully, all your hard work in the above steps will pay off and your plugin will be used and enjoyed by many people.
About the Plugin Developer
I’m Nick Ohrn, and I’m a web and application developer focused on enhancing the experience users have with their software. For web publishers, there are no better tools available than WordPress and Drupal. They’re easy to use and extensible, although somewhat bare bones to start with.
I’ve spent a lot of time learning the ins and outs of these two software packages, so if you need special functionality or have needs that aren’t met by the base software, I can help you. Simply fill out the quote request form, and I’ll get back to you within 24 hours. My prices are reasonable, and I guarantee your satisfaction.
Testimonials
I wanted to upgrade my Wordpress installation, but I had a dependency on two plugins that were incompatible with the latest version of Wordpress. So, a quick Google search and I found Nick’s site www.Plugin-Developer.com. I poked around and submitted my plugin request. A couple of hours later, I get a response and within a couple of days, Nick had already pumped out the first version of the new plugin. I was floored that he was able to turn it around so quickly. After a few iterations and bug fixing rounds (inevitable in the software development world), the finished product works like a champ. Overall I was very impressed with Nick and his ability to deliver what he said he would deliver–all within a 2-3 day window. I’ll definitely be back for more plugin help. Thanks!
Jason Mitchell — www.FeedTheHabit.comExcellent. Pre-Publish Reminders is a much needed plugin so thank you for keeping it updated.
Lorelle (of Lorelle on WordPress)
Comment