The Elon Musk Method for Writing WordPress Plugins

Some code

So, recently I coded up my first WordPress plugin. Nothing majorly impressive, but it did suddenly place me in some very rarified company, and that was a little intimidating.

I’ve recently joined Mastodon.  No I haven’t left  Twitter, but my engagement there is minimal (and has been for almost a decade).  It’s no longer the place it once was, and I have better things to do with my time.  Like writing some code (and maybe even another novel or ten).

One of the issues that Mastodon faces is that it’s so unknown.  Despite existing since 2016 it has only recently (Nov 2022) gained prominence in popular culture, as Twitter users sought an escape from the belligerence of Musk.  That means that there aren’t a lot of apps and other niceties that are common-place when using Twitter.  One of those is a widget that properly formats Mastodon feeds for display on WordPress.

Mastodon accounts come with their own rss feeds.  You can just use it to syndicate your (or other users) public toots to wherever you want to read or display them. Twitter also has a similar feature, but it’s much harder to syndicate.  However unlike Twitter, there’s no setting required with Mastodon, all your public toots are automagically syndicated.  Mine is available at https://aus.social/@skribe.rss.

One issue is that just like during the early days of Twitter, the RSS feeds aren’t formatted so that WordPress (and a whole host of other RSS readers) can digest and display them.  All because the individual items in the feed are missing a title.  Not having item titles  perfectly conforms to the RSS 2.0 specifications (it’s optional according to the spec), but the designers and coders chose to not allow for that implementation.  I heard one story that Twitter were strongarmed by Google to change their feeds to include the title.

How WordPress displays titleless feeds
How WordPress displays titleless feeds

So I wrote some code to take my Mastodon feed and add an item title.  It took only about 30mins to get it all working.  Then I made the mistake of trying to do it the WordPress way.  A week later I was still trying to decypher the obtuse API documentation for WordPress.

I complained (as I do), about the stupid titleless feeds, and about the even more indecipherable documentation.  Others heard my cries of anguish and a few added their voices to mine. 

One fellow even sent me some code to rewrite the feeds to include the titles.  It was long and detailed and must have taken many hours to write.  Yet I had no idea what I was supposed to do with it or even how it actually worked.  My own original code was only a handful of lines, and most of them were WordPress widget requirements.

Fortunately, the fellow happened to cc Dave Winer.  He designed the RSS spec.  The first thing he told the fellow was that he was doing it wrong.  That RSS wasn’t supposed to be used that way. I checked the spec and funny enough, he was right (who knew?).  Titles are optional. RSS readers should work without them.  He even dashed off some code demonstrating how it should be done.  Both with and without item titles.  Brilliant!  I’m certain it is.  I wouldn’t know because I’m not that fluent in javascript, but it does what it’s supposed to.

So, where did that leave me?  Still neck deep in WordPress API docs, but I had gotten my plugin to work the WordPress way  (finally!).  And despite my code not conforming to RSS expectations it works and it looks how I wanted it to work (that’s it in the sidebar).  I’ve since fixed some bugs and tightened up the code, and along the way I learnt a whole lot.  Mostly, never write another WordPress plugin.

One especially good thing occurred along the way, once the WordPress developers discovered Dave Winer’s displeasure at their implementation they resolved to fix the core RSS widget so that it worked with both titled and titleless feeds.  That’s a big win.  Yet, I’m still going to keep using mine.

It’s available here.

skribe

I’m skribe. I’m a writer, a film-maker and an actor. While I’m originally from Perth, Australia, I currently reside on a tropical island, the Lion City of Singapore. Fingerprint: 79A1 DC6C D367 8A31 135A 7AFA 940E 4231 D7B9 B15C If you like what you see buy me a coffee.

You may also like...