ChatGPT WordPress Plugins

This is kinda bananas.  Years ago I wrote a plugin to solve a problem I had.  I wanted a simple WordPress plugin where I could insert a shortcode into a blog post, specify a series title, and have it automatically search up all the other blog posts that used the same shortcode and series title, and then insert a nice looking list of blog posts in that series in chronological order.

It was one of my first plugins, still available on WordPress.org – just hidden since it hasn’t been updated in almost a decade.  It still works to this very day, if occasionally a little buggy.  After several WordPress versions, it no longer properly displays the series title, which is a real shame.

On a whim, I tried using ChatGPT to generate some plugins.

Here’s an example of my old plugin and the new ChatGPT written plugin (in this order):

Default Series Title

See how bad that was? It completely mangled the title.

Edit:  Since publishing this post, I realized that I would have to choose between

  1. Leaving the old defunct plugin in place just to make a point about how it didn’t stand the test of a decade’s worth of WordPress updates, but then also leaving broken series titles sprinkled through my back catalog of blog posts.
  2. Go back through nearly 10 years of blog posts12 to change them over to the new plugin shortcode.
  3. Disable the old plugin, but have the new plugin work with the old shortcode as well as it’s own new shortcode, at the cost of losing an example of how bad the old plugin performed.

I went with option 3.  Just take my word for it, it looked bad.

He makes a valid point

He makes a valid point

Now for the ChatGPT version:

Software Development with ChatGPT
  1. ChatGPT WordPress Plugins

It took me about an hour to whip up a working WordPress plugin with the same core functionality.  I would break down the time I spent as follows:

Time Spent Creating Series Plugin with ChatGPT

But, that’s not all!  You see, as I was writing this blog post, I realized it would be fun to include a pie chart to indicate the time I’d spent on this.  Unfortunately, the plugin I had written to do exactly this many years ago has apparently completely given up the ghost.  Thus, before I proceeded to this very sentence, I used ChatGPT to create a plugin for displaying custom pie charts!

Time Spent Creating Pie Chart Plugin with ChatGPT

Obviously, this plugin took a lot longer.  The first few versions were having all kinds of problems between the HTML Canvas code and trying to figure out how to make sure the javascript was not loading too early or too late.  In the end, I just asked it whether it was capable of even creating a pie chart – and it gave me a piece of workable javascript.  I told it to refactor the plugin using this same javascript, and then it was a matter of fine tuning the result.

If you don’t know anything about writing WordPress plugins, you could probably use ChatGPT to create a very simple plugin.  However, once it got slightly more complicated, it would likely require some troubleshooting to figure out what was happening.  In the series plugin it took me a while to root through the WordPress functions to figure out that apparently ChatGPT was trying to use a function in a way that simply did not work.  I explained to ChatGPT that that particular function could not operate in that way, explained how the data it was feeding into that function needed to be first modified, and then asked it to refactor the code.  From that point forward, it started to look a lot better.  There were some additional quirks – like putting more than one series title in a single post would only display one.  I suspect these problems of ChatGPT taking a shortcut to generate code, hardcoding certain variables and names, not considering that it might need to operate more than once on the page, may be difficult for it to anticipate and address.  Without some degree of WordPress development knowledge, I think a novice user armed only with ChatGPT would need to do a lot of refactoring, asking the program to generate the plugin all over from scratch many times, before arriving at a workable result.  Then again, a million monkeys at typewriters, right?

I think ChatGPT could be great for creating relatively simple plugins like a series plugin, a pie chart plugin, or even a table of contents plugin.  However, having seen how much time it cut out of the development process, I think it would be interesting to try developing an A/B testing plugin or more complicated plugin.

I think the next task to see if I can get it to generate QMK code for a keyboard, Arduino code, Raspberry Pi code, or a chrome extension.

I can already see some ways to improve both of the ChatGPT generated plugins used in this blog post.  My series plugin included two arrows at the bottom so the reader could navigate to the prior or next post in the series.  And I think it would be great if the chart plugin had a feature where I could specify the units, so the magnitude data would be included with the labels.  I may try getting it to shoehorn these updates later…

If you see these reflected in the charts above, I must have already done it.  :)

Software Development with LLMs
  1. Series Plugin Test for Illustrative Purposes Only
  2. ChatGPT WordPress Plugins
  3. Coding with an LLM Sidekick
  1. NGL, I can really be a lot some times. []
  2. Um, you’ve probably gathered that. []

OCD Plugin Stats and the WordPress.org Statistics API

What you get when you don't use an API

What you get when you don’t use an API

The current version of my WordPress OCD Plugin Stats plugin, is somewhat… clunky.1 When I wrote it I didn’t know that WordPress.org had an API for it’s plugin statistics.2 Thus, the current version essentially scrapes particular WordPress.org plugin pages for information and drops it into the WordPress dashboard.

After poking into the stats on one of my plugin pages the other day I discovered that the source code for the page included several calls to a WordPress.org API.  Why should I bother scraping and interpreting a page of HTML when I can just ask WordPress.org to deliver the exact data I need in a nifty JSON format?!  I’m very much looking forward to adjusting this plugin to use a more direct and simple call to the WordPress API rather than scraping plugin pages.

In any case, if you’re looking for documentation on this, I found a page in the WordPress Codex and a site with a page devoted to documenting the WordPress.org API.

Default Series Title
  1. Photo courtesy of peasap []
  2. Apparently they have more statistics than just on plugins []

ShrimpTest – how to fix incompatibilities with WordPress v3.3

ShrimpTest is a WordPress plugin with a LOT of promise.  Basically, it is an A/B testing tool for WordPress.  The plugin author, Mitcho, does a great job of explaining A/B testing and why it is important.  If you are already familiar with A/B testing, you can skip ahead to 16:03 in the video to see a demo of Mitcho presenting the plugin

Unfortunately, and this is truly a shame, the plugin also suffers from an almost complete lack of development and updating.  There must have been some change in WordPress v3.2 that stopped the plugin from working.  The effect was that the “A/B” icon in the rich text editor was missing.  Fortunately, someone figured out a work around.  The super quickest way to apply this change to the plugin is to do the following:

  1.  Make sure you’re logged into your WordPress website of choice
  2. Navigate to `http://[DOMAIN].com/wp-admin/plugin-editor.php?file=shrimptest/plugins/variant-shortcode/tinymce.js&plugin=shrimptest%2Fshrimptest.php`
  3. The second line down reads:
    1. ”     tinymce.PluginManager.requireLangPack(‘variant_shortcode’);”
  4. Comment out this line by adding two slashes before the code as follows:
    1. “//     tinymce.PluginManager.requireLangPack(‘variant_shortcode’);”
  5. Click “Update File”

You’re done!  Now you should be able to see the icon in your WordPress rich text editor.

Plugin Considerations

When designing/writing software, or I suppose any kind of engineering for that matter, there is always a tension between features and complexity.  I really want this Simple Series WordPress plugin to be simple and easy to use.  But, as I use it more and more I find there are some possible features that I wouldn’t mind having.

For example, my DrawBot series is at 43 posts at this moment.  The problem is that each post, no matter how short, now has an entire screen-length’s worth of a list for the series. 1  Now, there are several possible ways to handle this:

  • I suppose when I’m looking to design a UI, the most important things to focus on is what would the user expect to see and happen.  It certainly makes sense for there to be a uniform series list in every post.  But, it seems slightly inelegant to have it that way for every single post when you’re looking at an entire page.
  • I could modify the plugin so that it would only create a list once per page, rather than once per post.  I suppose subsequent instances could then provide a single link to the series list in the initial post.  I think this would be non-intuitive as a person navigated the page.
  • I could modify the plugin so that it only showed the current post plus X posts before and after where X is some arbitrary number I choose.  (Although, I’d probably make it user specifiable).  I’d have to dig into some fancy scmancy CSS to define a different start-number for the HTML ordered list, but this isn’t a huge problem.  Ideally, it would say there are Y prior posts and Z subsequent posts as well.  Then again, it is really helpful (at least to me) to be able to click back up or down through a series list.

Perhaps the optimal result is something in between?

  • On a page consisting of a single post, the entire list should be displayed.
  • On a page consisting of multiple posts, the subsequent lists should be truncated in some meaningful fashion.  Perhaps the last and subsequent X posts, with a little sentence indicating Y more prior posts and Z more subsequent posts.  When you click on the “Y more prior posts” it could take you to the first instance of the series list on that page and when you click on the “Z more subsequent posts” it could take you to the next post listed in the series on the first instance of the series list on that page. 2
  • Sadly, this system would not really change much for the RSS feed readers.
Default Series Title
  1. I can’t even imagine how much text is devoted to just the series list on those DrawBot posts in your RSS feed. []
  2. Um.  This sounded a lot clearer in my head as I typed it than it probably reads. []

Articles on writing WordPress Plugins

Looking back at one’s code from years prior is like looking back at a junior high school picture of one’s self.  I’m looking back at the code for my quick-and-dirty pie chart plugin and think, man, why did I write things THAT way?

In the 1,000 years since I wrote that plugin in 2009, I’ve been trying to learn and comply with best programming practices for WordPress plugins.  As a result my current plugins tend to be stripped down, simple, don’t create unnecessary options, don’t create unnecessary tables, taxonomies, special post types, or those kinds of things. 1  Learning some Object Oriented programming along the way has been super helpful.  By encapsulating your WordPress plugin code into a chunk of objected oriented programming, you reduce the likelihood that your plugins’ function and variable names will collide with those from WordPress or other potential plugins.

If you’re getting started or need to brush up on your WordPress plugin development skillz, you should definitely check out these awesome articles:2

I’d also recommend tinkering with jQuery and JSON, if you haven’t already. 3  I don’t know of any really good JSON tutorials, so if you do, please let me know so I can add it to this list.

  1. Admittedly, I’m not really shooting for super ambitious plugins either. []
  2. Mostly stolen from the WordPress Codex! []
  3. I only use JSON for passing data from the browser to the server via AJAX and then decoding into a PHP object. []

Simple Series with SEO! after just one day

I’m really happy to report that per the WordPress.org stats, this little post series plugin has been downloaded more than 100 times so far.  That’s really awesome.  And, now that I’ve figured out how to work this wacky SVN thing, I think it would be fun to release some of the other random little plugins I’ve developed over the last few years.

As of the latest version 1.4, the plugin is now easy to modify with some CSS added to your stylesheet.  I could have added this as a text field option a settings page for the plugin, but I really like the stripped down simplicity of the plugin as is.  Even with all the comment lines in the plugin, it is only 53 lines of code.  If super short code were a goal1 I could probably cut that in half.2

Now I have to find some of my old plugins that others might find useful.  I’ve got one for frame escaping, one for making pie charts…  I know there are a few other random ones as well.

Default Series Title
  1. And it isn’t []
  2. Obviously, I’m not going to do this since it would make the code next to illegible []

Simple Series WordPress Plugin

I’ve written a new WordPress plugin specifically designed to let you simply and easily create a series of related posts.  You can download Simple Series here.

1. What does “Simple Series” do?

Simple Series uses a WordPress shortcode to associate your posts together.  All you have to do is use the same shortcode in all of the posts you want to associate together and the plugin does the rest.  It will automatically find all of the posts with the same shortcode, organize them by publication date, and put them together in a professional and easy to read format.  If you wish to change the format, you can just add your own custom CSS to your theme.

2. How does “Simple Series” work?

Easy!  Just add the shortcode to each of the posts you want to put in the series.  Inside the shortcode you will need to specify the title for the series.  Like so:

Default Series Title

No problem!  The “Simple Series” plugin will always update the series lists in each of your posts whenever you publish a new post.  The newest post will always be added to the series in chronological order, by publication date.  You can see an example of what it looks like here in my own DrawBot series.

4. I have more questions!

Cool!  Please leave a comment to this post or send me an e-mail!

Default Series Title

WordPress Plugin Writing Resources

WordPress is easily my favorite open source software project.  I love it for it’s functionality, flexibility, and extensibility.  When it comes to writing a plugin, these are my favorite resources.  Don’t write a plugin without them!

  1. WordPress.org Codex for Writing a Plugin
    1. If you’re just getting started, this is the place to begin
  2. WordPress.org Codex Plugin API
    1. a great overview of the WordPress plugin API
  3. WordPress Action Reference
    • When WordPress displays a post, page, or the administrative pages it has to run through a number of functions and actions.  Your plugin will need to be activated at one of these points, and it is very helpful to know the order in which things happen.
  4. WordPress Filter Reference
    • The WordPress filter reference is a list of WordPress filters.  Each one will be able to deliver a little piece of the website for your to manipulate in your plugins.
  5. WordPress PHP Cross-Reference
    • The WordPress codex is pretty good – but it is not comprehensive.  If you want to know how some of the more obscure functions, variables, or constants work, you’ll just need to dive into the source code itself.  PHPXRef is, hands down, the best way to do this.  It let’s you search and read the the source code from their website.
  6. Top 10 Most Common Coding Mistakes in WordPress Plugins
    • This is quite possibly the best blog post about writing WordPress plugins.  Applying these guidelines will make you a better WordPress developer and your plugins faster, more efficient, and more awesome. :)
  7. How to Design and Style Your WordPress Plugin Admin Panel
    • In a lot of ways, a program is only as good as its user interface.  Build a good friendly and powerful interface and people will use your program.  Build a bad one and no one will use it, no matter how awesome it is.  This one blog post gives numerous little ways to make your WordPress plugin administrative interface look better.