Writing a WordPress Plugin

I just wrote my first official WordPress plugin and have it listed in the WordPress plugin repository! Import Blogroll With Categories

I discuss the plugin in a separate post: WordPress Plugin: Import Blogroll With Categories

Since this was my first official WordPress plugin, I wanted to document the procedure. Writing a plugin and going all the way with it, is not for the faint-of-heart.

First, you actually have to come up with an idea that:
1) No one has written a plugin for yet (search for it!)
2) Is doable without donating years of your life
3) Functionality you really want!

Then you actually have to create the plugin. You’ll probably have to use multiple hooks called actions and filters. I wish I could tell you there was some easy way to learn exactly which you use and how to use them, but it seems to be something you mostly have to figure out on your own. Studying the code of other plugins you like will probably help.

In PHP you can’t override user defined functions, but you CAN override all the WordPress functions defined in: wp-includes/pluggable.php. WordPress only defines the default functions if plugin defined versions don’t exist.

Various sites provide a comprehensive list of WordPress functions, classes, and variables and indicates within which files they are used and defined. WordPress provides a decent one.

Many editors (including Dreamweaver) include a method to search over all files within a directory. The feature goes by many names and is not always easy to find, but is a life-saver for tracking down functions/code.

The general WordPress plugin creation guide: http://codex.wordpress.org/Writing_a_Plugin

After your plugin has been created, relatively well tested, and refined, a whole different journey begins (if you want your plugin in the WordPress plugin repository).

I chose to put my plugin on wordpress.org because I think it is best place for WP plugins to reside. It makes the most sense to users. WP is integrated with the automatic plugin installer/updater. It serves are one solid place to look for plugins that are all documented in the same fashion. If you are serious about your plugin, I recommend you follow the required steps to get it up there.

You need to submit a request to add your plugin. The request has to approved by a person. I had to wait 2 days to get my request approved. When you make the request, make sure you use the plugin name you want to use, and a solid description.

When approved, you will get access to a SVN (Subversion) directory just for your plugin. Like this: http://svn.wp-plugins.org/name-of-your-plugin/

What they don’t clearly explain, is how to actually upload your files. The only page they refer you to is: http://wordpress.org/extend/plugins/about/svn/

Which is SOMEWHAT useful, but it is all in command-line. They make no reference to Subversion clients. When it comes to file transfer, I would prefer a nice GUI. For comparison, FTP is also a command-line based tool but we all use FTP clients don’t we?

After studying this chart of Subversion clients, I decided to try out SmartSVN (free)

I’ll admit it’s a bit overkill for updating a single plugin, but maybe I’ll use it for other SVN connections in the future. Once I got the authentication figured out (wordpress.org login), I had no problems using the program. It worked pretty much just like I expected. Easy to see if a file has been changed locally or remotely, and update the files.

SmartSVN has a ton of features, and I only used the basic stuff, so if I start using it more, perhaps I’ll write a post reviewing its features.

After uploading files (use the general guidelines here and here), you can expect to wait up to 15 minutes to see your changes reflected on http://wordpress.org/extend/plugins/

BEFORE you upload anything you’ll want to do the most important thing. To create a VERY specifically formatted readme.txt file. This readme.txt file is used to CREATE your plugins page at: http://wordpress.org/extend/plugins/your-plugin-name/

You don’t have special admin access to update that page. The page is entirely controlled by the contents of your SVN directory (especially the readme.txt).

Because the readme.txt file is so important, WordPress provided a couple nice resources. An example readme.txt file containing notes about how to format your text. And a readme.txt validator. The validator is sweet. Not only does it validate your file, but it gives you a PREVIEW of the generated HTML formatting. This preview will help you work out formatting issues before you upload anything to your SVN folder.

Remember, your plugin will be live (in about 15 minutes) after you first upload your plugin file and valid readme.txt file. So try to already have a complete and properly formatted readme.txt file before you upload anything.

Leave a Reply

Your email address will not be published.