Advertisement
WordPress

The Ultimate Guide to Building a Wordpress Plugin

by

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.

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
  • Code
    Tips
    New wp-config Tweaks You Probably Don't Know8 new wp config tweaks you probably didnt know about 400
    The wp-config.php file: One of the most loved WordPress feature for some, one of the worst nightmares for others. There are countless tips and tricks in a plethora of articles, and you can't get enough of them; however, this article is aiming to be different. In this article, we're going to get familiar with eight new wp-config tricks that are less known than functionality such as turning off post revisions, increasing the memory limit, or other similar features.Read More…
  • Code
    Web Development
    How to Use New Relic With PHP & WordPressRelic retina preview
    Today we will look at how to monitor a PHP application using New Relic. More specifically we will set up a basic WordPress installation and get some performance data about it, in the New Relic dashboards.Read More…
  • Code
    Mobile Development
    In the Spotlight: Brian LeRouxPreview image@2x
    The explosive growth of the mobile space has accelerated the search for a robust and viable cross-platform solution. In 2008, shortly after the introduction of the iPhone SDK and after fiddling with Cocoa and Objective-C, Brian LeRoux and his colleagues at Nitobi decided that their time was better spent building a cross-platform solution than building native mobile applications.Read More…
  • Code
    Theme Development
    Creating a WordPress Theme From Static HTML: Releasing Your ThemeCreating wordpress theme from html 400
    If you've been following this series you now have a working WordPress theme. Your theme has a number of template files, including a page template and an archive template, and also has featured image support.Read More…
  • Code
    Creative Coding
    Using WordPress for Web Application Development: A ReviewApplication foundation 400
    Over the past few months, we've been taking a look at all of the features and aspects that make WordPress a potential foundation for application development. In fact, we've spent roughly 15 articles talking about all that WordPress offers. And though we'll be reviewing each of the points in this email, perhaps the biggest thing to take away that building web applications using WordPress is different than using many of the popular frameworks that are currently available namely because WordPress isn't a framework.Read More…
  • Code
    Theme Development
    Making the Perfect WordPress Theme: How to Code WellWp white 400
    In the previous part of this series; we went through various WordPress APIs that we should learn about, talked about the importance of making a theme translatable (or even better, releasing them already translated into other languages) and understood the concept of licensing themes and using licensed products with the themes. In this article, we're going to focus on code: We'll see how to code with WordPress coding standards, how to properly comment our code and how to validate and test the theme.Read More…