Glen Stansberry posted a good guide to building a wordpress plugin on nettuts.com and I thought that it was worth re-posting here for those of you who have considered building your own wordpress plugin. It’s really good information.
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:
- Wordpres’ AJAX page
- AJAX in WordPress plugins
- Simplified ajax for WordPress plugin developers
- jQuery and Ajax in WordPress plugins
- jQuery and ajax in WordPress plugin administration pages
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.
The Ultimate Guide to Building a WordPress Plugin – NETTUTS
Questions or Comments?