The Ultimate Guide to Building a Wordpress Plugin

Dec 29th in Articles by Glen Stansberry

When it comes to adding extra functionality to a Wordpress blog, Wordpress users typically go and search for a plugin that might suit their needs. There are often plugins created for basic extended functionality, but what happens when you can't find the perfect plugin for your needs? It might be easier to just create the plugin yourself.

Wordpress has an excellent plugin framework that makes extending the core Wordpress functionality quite easy. In fact, making a simple plugin is surprisingly uncomplicated, thanks to the excellent Wordpress documentation and other helpful articles around the web.

If you think you'd like to take the plunge into writing a Wordpress plugin, here are some essential resources and tips to guide you on your way. This will carry you from the earliest stages of plugin creation to promoting your newly-created plugin, and everything in between.

PG

Author: Glen Stansberry

Glen Stansberry is a web developer and blogger. You can read more tips on web development at his blog Web Jackalope or follow him on Twitter.

Plan Before You Build

If your main motivation isn't to solve a specific need for a plugin, than there are many other ways to generate ideas and reasons to write a Wordpress plugin. Sure, you could always whip up the simple "hello world" plugin (provided in the default Wordpress installation), but we want something a little more challenging, right? If your plugin idea seems simple enough to create from scratch, try using your plugin idea as your sample application instead of spending time building a useless application that you'll never use, just for practice.

If you'd like some more ideas for building a plugin, DevLounge has created a list of ways to generate ideas for writing Wordpress plugins. Generally, the best practice is to start researching other existing plugins and work on ideas to improve them.

Gather Powerful Tools

You can't start building your plugin without setting up a proper test environment. Here are some must-have tools for building a Wordpress plugin:

  • Firefox - If you've yet to install Firefox on your computer run, don't walk, over to Mozilla and snag a download of the superior web browser. It's an incredibly useful tool for web developers.
  • Firefox Extensions - There are two really good Firefox extensions that make debugging and designing your plugin much less of a chore: Firebug and the Web Developer extension.
  • Wordpress - You'll need a clean install of Wordpress so that you can set up your testing environment on your computer.

Gather Good Information

Aside from this post, you'll need some other documents that allow you to quickly find Wordpress plugin API references. Here are a few that will come in handy:

  • Wordpress' Plugin Resources - Reference guide for all things Wordpress plugins. Tutorials and how-tos galore.
  • Wordpress Plugin API - This is your lifeline, your cheat sheet of everything that comprises a Wordpress plugin. If you're ever stuck, this is the document you'll go back and reference for help.
  • Plugin API Action Reference - The list of actions that are available in Wordpress plugins.
  • Plugin API Filter Reference - The list of filter hooks that are available in Wordpress plugins.
  • Wordpress IRC Channel - Fire up your favorite IRC client to access this pool of Wordpress developers who are willing to help with your plugin creation woes.

Create a Dedicated Test Environment

Now that you've gathered your tools and resources needed to create a plugin, it's time to set up your test environment. There are two different methods of setting up a plugin test environment. The best way to speed up your development time is to create a testbed on your own computer, using Apache and MySQL. While this can be a bit more advanced, there are tutorials for setting up different Wordpress environments with both of these technologies.

For developing on a Windows machine, try installing Wordpress using XAMPP, a nifty program that bundles Apache and MySQL together in an easy install. (Note: XAMPP is cross-platform, so Linux and Mac users can use it too.)

Another option for Mac users is to install Wordpress using MAMP, a program that bundles MySQL and Apache for use on Macs.

The second option for test environments is to just make a separate directory on your webserver and create a fresh install of Wordpress on that. You'll have to upload every change using FTP, so it will be much slower than a local test environment.

Master the Basics

Fortunately for unskilled programmers like myself, building a Wordpress plugin can be a relatively simple process. Sure, you can make incredibly advanced plugins, but it's quite easy to just dive into creating a simple plugin with the framework that Wordpress has set up.

Jarkko wrote an article on earlier this year on the anatomy of a Wordpress plugin, and this is an excellent place to start with the basics of plugin writing. The tutorial shows how to create a simple plugin that creates a widget that shows upcoming scheduled posts on a Wordpress site. A perfect resource for any beginner, complete with source files.

Access and Manipulate Database Data

Database interaction is crucial to nearly all plugins, so it's important to understand the basics of how to connect to the Wordpress database and access data. The Wordpress documents have an excellent tutorial on how to interact with databases.

Utilize Javascript and CSS

While some plugins might not need any extra styling, adding a little spice to your plugin never hurt. DevLounge has a great article on how to include elements like Javascript and CSS into your plugin.

Ajax is another element that can really make a difference in a Wordpress plugin. Sending data without needing a page refresh is a useful attribute to have in your plugin. Here are some resources on how to utilize Ajax in a Wordpress plugin:

Add a Versatile Options Page

Your plugin might require an Options menu and page to show configurable choices for the Wordpress administration section. The Wordpress Codex has a great reference page on adding administration menus. If you're wanting a tutorial with screenshots, then try Wordpress Bits' Adding Options to Wordpress tutorial.

Internationalize It!

A useful way to spread the reach of your plugin is to translate it into different languages. The Wordpress plugin framework allows developers to localize the plugin, allowing for different translations to be made.

Spread it to the Masses

Here a few of the main resources to publicize your kickin' plugin and allow other Wordpress users to download it:

  • Wordpress.org's Plugin Directory - The official Wordpress site is far and away the best place to promote your plugin. It has an extensive plugin directory that many Wordpress users find plugins with. Just register an account and upload your plugin. The plugin will have to be approved by Wordpress.org to make sure that it follows their plugin guidelines.
  • Weblog Tools Collection - You can submit your plugin to Weblog Tools Collection, a widely-read blog on blog tools and plugins.
  • Wordpress Forums - You can use the Wordpress forums to find beta testers for your plugin, to make sure the plugin is free of bugs and ready for "prime time".
  • Plugin Submission and Promotion - The Wordpres Codex has a great resource on how to get your plugin in front of testers and other Wordpress users.

  • Subscribe to the NETTUTS RSS Feed for more daily web development tutorials and articles.

Glen Stansberry is a web developer and blogger who's struggled more times than he'd wish to admit with CSS. You can read more tips on web development at his blog Web Jackalope.

Liked this post? Vote for it on Digg below. Thanks!


Related Posts

Check out some more great tutorials and articles that you might like

Enjoy this Post?

Your vote will help us grow this site and provide even more awesomeness

Plus Members

Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.

Join Now

User Comments

( ADD YOURS )
  1. PG

    Daniel Morgan December 29th

    First! Just joking! No but really… my first comment!

    Will read now lol, enjoy learning about Wordpress!

    ( Reply )
  2. PG

    Brenley Dueck December 29th

    Great list of resources Glen! There are the few times when you can’t find a plug-in to suit your needs and need to build yourself one.

    ( Reply )
  3. PG

    M.A.Yoosuf December 29th

    ultimate guide

    ( Reply )
  4. PG

    Gaz December 29th

    Ohh… I thought we’d be making a plugin!

    ( Reply )
  5. PG

    iEthan December 29th

    I also thought we’d be making a plugin… but no matter. This is a nice list of resources, none-the-less.

    ( Reply )
  6. PG

    DVQ December 29th

    Great write up, but I would now like to see another plugin creation tutorial.

    ( Reply )
  7. PG

    Fauverism December 29th

    Nice article! Rekindled some ideas that i’ve had for plugins in the past.

    ( Reply )
  8. PG

    Ahad December 29th

    Yup i guess i did too. I think the article should have been named “The Ultimate Guide to [Planning] a WP plugin.”

    What plugins does everyone use?

    I use these, just to name a few:

    (1) phpwidget
    (2) Headspace
    (3) WP Backup
    (4) Yoast Breadcrumbs
    (5) Geishi Sytax Highlighter/Code Colorer
    (6) C Forms
    (7) Kimli (Need to get rid of it!)

    Plus lots of inactive ones, which i’ve gotten rid of…

    ( Reply )
  9. PG

    insic December 29th

    ultimate guide indeed.

    ( Reply )
  10. PG

    Papa Smurf December 30th

    slow news week?

    ( Reply )
  11. PG

    OpenSourceHunter December 30th

    Always good to see stuff about wordpress :D

    greetz,
    http://www.opensourcehunter.com

    ( Reply )
  12. PG

    Armored December 31st

    Yeah… this one doesn’t really fit in with the other great tutorials in here… Just another list of links generated from your bookmarks…

    ( Reply )
  13. PG

    Jack December 31st

    Thanks Glen, I’ve been looking for something like this. The official WordPress docs aren’t so great for helping a beginner make their first plugin, but this certainly is!

    ( Reply )
  14. PG

    Jonathan Thomas January 2nd

    I’m looking to take a simple php directory script and turn it into a plugin so that it displays in wordpress.

    Does anyone know where I could find info on how to do this quickly? My programming knowledge is very limited.

    ( Reply )
  15. PG

    Krisditya January 6th

    Nice article Thank you!

    ( Reply )
  16. PG

    Davor January 7th

    Great summary what to do…

    ( Reply )
  1. Arrow
    Gravatar

    Your Name
    January 7th