BRYGS logo

On Writing a WordPress Plugin

Mar 4, 2022 | Technology | 0 comments

In December of ’21, I wrote my first WordPress plugin for something other than my own use. That plugin was “PetPress”, a plugin connector for PetPoint and WordPress. In January I submitted it to WordPress.org for inclusion in their catalog, and after a little back-and-forth (described below), it became the first and only plugin of its kind in the catalog, which I have to confess I’m pretty proud of.

Why I wrote a WordPress plugin

The PetPress plugin, which connects PetPoint to WordPress.

I had essentially three goals when I decided to create a WordPress plugin. The first goal was to extend the functionality of some code I had already written. I wrote a PetPoint / WordPress connector for an animal shelter that I volunteer for, and used a file-based mechanism to cache the pages that were generated. This was necessary because the interface isn’t particularly fast, and multiple calls are needed in many cases. By making a WordPress plugin, I knew I could leverage the MySQL/MariaDB database that the WordPress site uses to move caching to the database rather than having to use the file system. Plus, I wanted to be able to use WordPress tools (specifically, Divi) to format all of the parts of the site that aren’t generated by the interface. (My original site was all hand-written, which is very laborious when dealing with both variable content and the needs of responsive design).

My second motive for turning my PetPoint/Wordpress interface into a plugin was, believe it or not, to help out other people. PetPress is the #1 kennel management software in the USA (or, at least it was according to stats from 2014) and WordPress is the #1 content management system on the web (accounting for something like 40% of Internet sites). Being able to connect the two should make it dramatically easier for many, many animal shelters to provide pet listings directly on their websites (without having to use the more rudimentary tools offered by PetPoint). These are organizations that never have much money, and it was pretty cool to think that I could help potentially hundreds of shelters out.

My third motive was to hopefully generate some income. I’m hoping that some of the users of the plugin will want help either integrating it or help with the broader challenge of creating or updating their websites. There happens to be “donate” links all over the place, but as of this writing (nearly two months since release) the donate links have generated exactly $0, and I’m not hopeful that that will change. It is such a common model on the Internet that software and information is given away “for free” in exchange for advertisement revenue or data collection on the (often unsuspecting) buyer that people have just come to expect that Internet software is free.

Submitting the WordPress plugin to WordPress.org

Anyone can write a WordPress plugin that can be installed fairly easily without submitting it to WordPress.org, and in fact if your primary goal is to sell your plugin then you probably want to avoid the WordPress.org catalog completely. However, there are some unique advantages to having your plugin in the catalog.

Probably the biggest reason to put your plugin into the catalog is that it’s the easiest place for people to find it. The WordPress administrative interface for plugins allows a site builder to search the catalog directly from the admin section. If the plugin isn’t in the catalog, the next option is to install a plugin manually. That’s not difficult: it’s just a matter of uploading a .zip file, but of course you have to have the file to upload, which means finding it on your own.

Having WordPress.org include your plugin into the catalog also confers a certain authority to it. A rather strict set of tests are made to (hopefully) ensure that the plugin doesn’t pose a security threat for the site it runs on and that the plugin will not interfere with others. All things being equal, it’s reasonable to trust a plugin from the WordPress.org catalog over one that is sourced elsewhere.

One of a couple of highly detailed feedback emails from WordPress.org regarding my plugin submission.

The first time I submitted my plugin, I fairly quickly received a reply with a short list of corrections that had to be made. It took a couple more tries to get it all right, but within a week or so of starting the process, my plugin was accepted.

What I learned

The first lesson from submitting a plugin to WordPress.org was about their use of namespaces. Every function, variable, etc. in a plugin must be unique, and I suppose that means that every plugin on your site can theoretically call every other plugin. This is at the same time fascinating and pretty worrisome. It’s hard to see this sort of thing flying in the present day, but it is the reality in WordPress land. It certainly makes plugins powerful, that’s for sure.

Another lesson had to do with how serious they take the sanitizing of I/O. There were a number of functions in my plugin which seemed completely safe to me, but whose output still needed to be run through various WordPress functions to sanitize. These folks have been at this a long time, and it’s hard to argue that they aren’t doing things the right way. It’s a little extra trouble for the developers, but one does need to be careful these days.

I was extremely impressed with the communication I received from WordPress.org during the submission process. I think my code must have been run through some automated checkers, just based on how quickly I received my feedback (usually the next day). I’d be inclined to suspect that the code was only run through some automated checkers, but when things got very granular at the end I did receive some highly personalized feedback from the reviewer. Somebody really did take the time to answer my questions and provide feedback. And the lengthy emails I received were highly informative even when a lot of it must have been boilerplate. All in all, I certainly felt better shepherded through this process than I was years ago with my first iOS app submission (though maybe that’s better these days, too).

Would I do it again?

I’m not sure when I’ll have the opportunity to write another WordPress plugin. The main reason is I’m not sure when I’ll really have something that I think would be a worthwhile contribution. There are a zillion plug-ins out there, and I can usually find one that does what I need it to without having to write my own code. Still, if I do come up with some idea that would make a great plug-in, I would definitely go for it. I might spend a little more time thinking about how to monetize it, though, because the donations concept is not a winner.

In closing, if you have a killer idea for a plugin and would like to hire me to build it for you, you know where to find me!

 

0 Comments

Submit a Comment

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