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.

Comments

  1. That's pretty cool. I've thought about building WP plugins before but I never have any ideas for them. At least, ideas that weren't already done and already done well.

  2. vegasgeek says:

    Thanks, Robert! Finding something that hasn't already been written is tough. What you need to do is find something specific that hasn't been covered before. Believe me, mine is nowhere near the first plugin to let people display ads on their site. But, by throwing in the option of showing it only on older posts, that made mine different enough that I felt compelled to write it.

    If you are interested in working on a plugin together, I have a pretty decent idea for a rather complicated plugin that may have elements that are over my head.

  3. Richard says:

    It is amazing what you can do with the right documentation, it can be a lot easier to write in those languages, thanks for the heads up i didn't know they were so on top of things.

  4. If you are interested in working on a plugin together, I have a pretty decent idea for a rather complicated plugin that may have elements that are over my head

    "I am Interested"

  5. Sharee says:

    What an accomplishment!! One of the many things I love about your blogs is the added information. All the research for creating a plugins for WP is on this post! You saved time for many others! Great accomplishment again!

  6. Andy says:

    I should say that you good information for other bloggers

  7. Gill says:

    Congratulations! I've dabbled in WP plugins as well. From my experience it can be tricky though to get them to work between different versions of WP. I've had situations where my plugins stop working with upgrades to WP. But the portability you get is worth it. Have you considered sharing your plugin or making it available for download?

  8. vegasgeek says:

    Gill, thanks for the comment.

    My plugin is available for download here: http://wordpress.org/extend/plugins/ads-for-old-p

  9. vegasgeek says:

    Gill, thanks for the comment.

    My plugin is available for download here: http://wordpress.org/extend/plugins/ads-for-old-p

  10. vegasgeek says:

    Gill, thanks for the comment.

    My plugin is available for download here: http://wordpress.org/extend/plugins/ads-for-old-p

  11. vegasgeek says:

    Gill, thanks for the comment.

    My plugin is available for download here: http://wordpress.org/extend/plugins/ads-for-old-p

  12. vegasgeek says:

    Gill, thanks for the comment.

    My plugin is available for download here: http://wordpress.org/extend/plugins/ads-for-old-p

  13. vegasgeek says:

    Gill, thanks for the comment.

    My plugin is available for download here: http://wordpress.org/extend/plugins/ads-for-old-p

  14. vegasgeek says:

    Gill, thanks for the comment.

    My plugin is available for download here: http://wordpress.org/extend/plugins/ads-for-old-p

  15. Colin Waters says:

    Awesome plugin you've made. I can definitely see how this is something really useful for bringing in some extra cash flow

  16. Great article I was searching for how to create a plugin.. I'm going to read the link you posted, since I too have a few ideas but have no Idea how to create a plugin. Thx again