Building a plugin

I've always thought it would be cool to write my own WordPress plugins. Plenty of times I've taken existing plugins and tweaked them here or there to do a slightly modified version of their original intent, but never have I started from scratch and created my own plugin. Until now, that is.

Last week I decided I wanted to place an advertisement in the main body of blog posts on my site. But, I didn't want these ads to show on recent posts. Instead, I wanted to make them show up only on posts that are older than 30 days. Initially I went in to the WordPress theme and added the code directly in to the template. My plan worked perfectly and the ads were now showing on old posts, but not on new ones. Once I realized how handy this chunk of code was, I decided I may want to use it on other sites, and other people may want to use it, too. That's when I decided to turn it in to a plugin.

When we went to WordCamp Denver, I sat in on the Plugin Workshop hosted by Shawn Parker from Crowd Favorite. I remembered one of his slides had a list of all the places you could hook in to WordPress to perform your own actions. I was happy to find that he had posted his slides online and also included the sample plugin that he created during the presentation. I used a combo of these two pieces of information to create the first version of the plugin. My new plugin was crude and not ready for public use, but, it worked!

If I wanted anybody else to be interested in using the plugin, I knew I was going to have to create an admin section that would let people set up their own ads. I checked out several other plugins to see how they were going about it, but I couldn't find an example that gave me exactly what I needed. Then I found the following article on the WordPress site: Adding Administration Menus. The fog had been lifted. 45 minutes later my plugin was fully functional, admin section and all. After a few hours of testing and tweaking, my plugin was ready for prime time. I zipped it up and released it to the world.

I would love to say that's the end of the story, but no. Next I wanted to get my plugin listed in the WordPress plugin repository. This way, any WordPress user would be able to find my plugin and install it directly from their WordPress admin panel on their site. This would open my plugin up to several million potential sets of eyes. Far more than the number of visitors I have on my site. 😉 Once again, WordPress documentation came to my rescue. The Plugin Submission and Promotion article explains the steps needed in order to get your plugin listed. After my initial submission was approved, I uploaded my files and my plugin was now available in the WordPress plugin repository.

It's no secret that WordPress is easy to install and easy to use. But what most people don't know is how incredibly well WordPress is documented. If you ever decide to write your own WordPress plugin, do yourself a favor and start by reading the Writing a Plugin article. It is filled with great information and links off to more detailed instructions for each of the major parts you'll run in to along the way.

Now that I know the basics, I'm really interested in turning some other ideas I have in to WordPress plugins. Stay tuned.