Building a WordPress plugin
Today I started working on a WordPress plugin (I’ll tell you more about it soon). To do that I needed to brush up a bit on my plugin-writing skills. I’ve always found making WordPress plugins unnecessary frustrating but as I searched for some articles about it today I found this:
Since WordPress 2.8, building widgets has been a matter of extending WordPress’ own widget class, WP_Widget, resulting in your custom widget only having to focus on 4 main functions:
- Initialisation (__construct) – handles actions to take when the widget is first created such as enqueueing specific javascript or stylesheets in the output
- Front-end display (widget) – handles the generation of the widget’s HTML output
- Back-end form (form) – handles the generation of the form controls that make up the widgets edit interface in the Admin interface
- Update (update) – handles the form submission from the back-end form, updating stored data as necessary
I had completely missed this. In my mind plugins was still this boiler-plate filled bag of hurt. Instead all you got to do is subclassing WP_Widget and replacing a couple of methods. Wow!
As I took the approach suggested in the article and based my code on the sample code in it, I got up and running super-quick. A beta version of the plugin is actually running on my local machine already, after maybe an hours worth of work. The fact that it was so easy makes me very happy and gives me the urge to write more plugins.