WordPress Widget Boilerplate

October 3, 2011 — 21 Comments

A few months ago, I contributed an article to WPTuts on Writing Maintainable WordPress Widgets. The motivation for this series was driven largely by the fact that as much as I love the WordPress community, there are more than a few poorly constructed plugins.

In some cases, this is fine. If you’re planning to quickly throw something together with no plans to continue development after its initial release, you can probably get a way with throwing something functional together.

But if you’re looking to build a plugin that you’ll be maintaining over time, then I believe applying good software development practices is a must. That is, I think that developers should follow the platform’s API, use design patterns where applicable, and clearly organize their files.

Over the past year, I’ve written a number of WordPress plugins both for contract and for hobby. During that time, I began creating a boilerplate of code off of which I build most of my widgets.

The WordPress Widget Boilerplate features the following:

  • File Organization. The Boilerplate ships with both JavaScript sources and stylesheets for both the administrator and the client-side views. It provides a basic localization file to make it easy to localize the plugin. It also includes a stubbed out README that follows WordPress conventions.
  • Documented Code. Each file of the plugin and each method of the core code is clearly documented for its purpose in the overall plugin. Additionally, the core code includes various TODO’s to make it easy for your IDE to locate everything you need to populate when working on your plugin.
  • API Implementation. The Boilerplate is based on the WordPress API in order to enforce best practices when building on top of the WordPress platform. This makes it easy to develop conventional, familiar code and makes it easy to compare your work with the recommendations of the Codex.

The WordPress Widget Boilerplate is available on GitHub and is under active development. Feel free to watch, fork, or contribute. I’m always looking to make it as solid as possible when it comes to plugin development.

21 responses to WordPress Widget Boilerplate

  1. Sunira October 3, 2011 at 3:30 pm #

    This is, um, totally fantastic.
    Thank you!

    • Tom October 3, 2011 at 3:37 pm #

      ;)

      I’ve got one for plugins, too. Gonna write about it later.

      • Vadim October 13, 2011 at 6:28 am #

        This is very useful! Cant wait for the plug in one as well..

        • Tom October 13, 2011 at 7:51 am #

          There are a few more changes that I want to make to the Widget Boilerplate then I’m going to revisit the Plugin Boilerplate :).

  2. Pieter October 13, 2011 at 5:18 am #

    Great share. Thank you, I’ll use it. This should be included in the WordPress documentation.

    • Tom October 13, 2011 at 7:50 am #

      Ah, I appreciate that. There are still a few changes that I need to make (so keep an eye on the GitHub project :).

  3. AR October 13, 2011 at 5:23 am #

    Thanks Mr.Tom :)

    • Tom October 13, 2011 at 7:50 am #

      You’re welcome!

  4. jeFFF October 13, 2011 at 5:26 am #

    Hello,
    This look really interesting and I needed this kind of development for my own projects.
    Thank you for that ;)

    Cheers
    jeFFF

    • Tom October 13, 2011 at 7:51 am #

      Awesome – thanks Jeff!

  5. ngassmann October 13, 2011 at 7:48 pm #

    Can’t wait for the plugin boilerplate.

  6. Janne November 18, 2011 at 8:12 am #

    this is great. but is it me or is the body text on your site almost illegible?
    looks like a very very light helvetica neue here, hurts my eyes!

    • Tom November 18, 2011 at 3:29 pm #

      Thanks!

      Noted the styles – I’ll look into it later :).

  7. Mark Simchock November 18, 2011 at 11:24 pm #

    Two words…Oh my.

    Two more if you don’t mind…Thank you.

    • Tom November 18, 2011 at 11:25 pm #

      LOL – of course! Thanks for the comment :).

  8. Mark Simchock November 19, 2011 at 12:11 am #

    p.s. Any progress on the plug-in version?

    • Tom November 19, 2011 at 12:27 am #

      Unfortunately not just yet – been working on other projects. Planning to try to have it out by the end of the year, though!

  9. Nate Arnold October 25, 2011 at 10:15 am #

    Thanks for this! On another note… your comments form tripped me out for a minute because the labels are below the boxes : )

  10. Tom October 25, 2011 at 10:21 am #

    Sure thing!

    And which browser are you using (or can you shoot me a screen shot)?

Trackbacks and Pingbacks:

  1. Wordpress Widget Boilerplate | Essential Wordpress - October 13, 2011

    [...] anyone looking to write their own widget for WordPress, this boilerplate seems like a particulary good starting point. This entry was posted in Uncategorized by [...]

  2. WordPress Widget Boilerplate – An organized, maintainable boilerplate for building WP widgets - CodeVisually - October 19, 2011

    [...] WordPress Widget Boilerplate ships with both JavaScript sources and stylesheets for both the administrator and the client-side [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>