I asked ChatGPT to write a WordPress plugin I needed. It did, in less than 5 minutes
![OpenAI logo on laptop surrounded by books](https://www.zdnet.com/a/img/resize/455ec3e843def5f247f3b15e6db5c8e44c48f969/2023/02/06/c0baa3d3-1ef2-473e-8cba-7529da51077e/gettyimages-1246766124.jpg?auto=webp&width=1280)
Not to put too fine a point on it, I’m more than a little freaked out. As an experiment, I asked ChatGPT to write a plugin that could save my wife some time with managing her website. I wrote a short description and ChatGPT wrote the whole thing: user interface, logic, and all.
In less than five minutes.
Also: How to get started using ChatGPT
There are implications. We’ll get to that in a few minutes. First, let me take you through the experience and what went down.
The need
ChatGPT wrote the plugin that generates this UI and processes the lines. David Gewirtz/ZDNET
My wife is the proprietor of a WordPress-based e-commerce site focused on a popular hobby. She also hosts a very active Facebook group for customers of her site. Every month she randomizes a list of names, and then does a virtual wheel spin animation, using that randomized list, for the Facebook group. She has been using a site on the internet that does a fair job of randomizing lines, but charges a bit more than it’s worth for exporting the list.
Also: Can AI detectors save us from ChatGPT? I tried 3 online tools to find out
As I watched her struggle to get the randomized names back out, I thought it might be helpful if I wrote a quick WordPress plugin we could install on her site. She’s in the dashboard every day, so having that as a tool would be helpful.
But even a simple plugin would take me a few days to write, what with the user interface elements and logic code, and I’m pretty full up on projects these days.
And then I thought of ChatGPT. There’s been some discussion about ChatGPT as a programming tool in the media, so I decided to give it a try.
The prompt
Output from ChatGPT (from my first, most basic prompt) David Gewirtz/ZDNET
The key to getting ChatGPT to generate anything is a carefully written prompt. In the case of programming, think of it as being a manager or client. You have to clearly describe what you need in order to get what you want. I started with a very basic prompt, just to see if it would work. Here’s the prompt I used:
Write a PHP 8 compatible WordPress plugin that provides a text entry field where a list of lines can be pasted into it and a button, that when pressed, randomizes the lines in the list and presents the results in a second text entry field.
Within a minute, it generated the code you see to the right. I copied the generated code into a .php file, put it into a folder with the same root name as the .php file, compressed it, and uploaded it to her server. It worked.
When I showed it to my wife, she was suitably impressed and surprised. But then the gears started to turn and she asked for a new feature: make sure duplicate names are not side-by-side.
For her application, she’ll sometimes need to include someone’s name on a list many times over. But she didn’t want those duplicates to cluster.
I modified my original prompt, adding the following additional conditions:
…makes sure no two identical entries are next to each other (unless there’s no other option)…with the number of lines submitted and the number of lines in the result identical to each other.
I included the “unless there’s no other option” phrase and the identical count requirement because I wanted to make sure all the names were included, and I was concerned that it would prioritize the need for no two names to be side-by-side over keeping all the names.
About 30 seconds later, I had a new plugin. I uploaded that one to the server and tried it out. It worked, but the output included some blank lines. So I added this condition to my previous prompt:
…with no blank lines…
By now, I’d grown accustomed to the turnaround time, which was always less than a minute. One more upload and test, and again, it worked.
I wanted one final feature, just to confirm how many lines had been processed. I wanted the plugin to show a count of lines for the entry and output fields. Here’s that prompt addition:
…Under the first field, display text stating “Line to randomize: ” with the number of nonempty lines in the source field. Under the second field, display text stating “Lines that have been randomized: ” with the number of non-empty lines in the destination field.
This worked, mostly. Before running, the output field shows one line. But once the randomize process is completed, it shows the exact right number of lines in both fields.
The code quality
Overall, the code quality was clean. I’m only presenting the original response because otherwise it wouldn’t fit in the article. The program properly generated the WordPress header block and wrote the dashboard user interface for the plugin, as well as the plugin’s processing logic.
It did put my summary lines above the fields, even though I specified below, but that’s not a big complaint. It’s the same sort of mistake a client might get back from a human contractor, and then require a bit of rework to fix.
Also: Can Notion AI writing helper write this article?
Coding worked, but it didn’t incorporate all the best practices for WordPress programming. For example, it didn’t sanitize the user input. The WordPress community is rigorous about sanitizing input so hackers can’t stuff fields with data that can corrupt a site — and this code had none of that.
As a later test, I did instruct the Ai to sanitize input, and it did… to a point. It sanitized the input inside the PHP function, but it did not sanitize the input when calling PHP within HTML. That would have definitely left an opening for hackers.
It also dropped the plugin’s menu item into Settings. I probably would have put it under Tools or given the feature its own menu item. Since I didn’t specify where it should be invoked from, I think ChatGPT made a workable decision in placing the menu item where it did.
I added one final requirement to my prompt, requesting the AI give the plugin a name:
Write a PHP 8 compatible WordPress plugin called “Robo Randomizer” that…
Weirdly enough, the AI gave me an entirely different plugin, generating a plugin that provides a shortcode rather than a dashboard interface. Let me explain that to non-WordPress users, because it’s interesting.
When writing something like this, you can make it available on the website to visitors (called the frontend) or to those who log in to the site’s dashboard to maintain the side (the backend). In my original set of prompts, I did not specify frontend or backend, but the AI wrote what I wanted, which was a backend, dashboard interface for the tool.
Also: OpenAI is hiring developers to make ChatGPT better at coding
But this last time, it decided to write the plugin as a frontend tool, making it execute through a shortcode. In WordPress, you can embed a shortcode (something like [randomize lines]) within a post and it will run code in a plugin. The last version that the AI produced gave me such a shortcode, which would have allowed the randomize lines feature to be presented to site visitors.
After this, ChatGPT kind of lost the thread. I wasn’t able to get additional features added to the original plugin and ChatGPT mostly just repeated generating the shortcode version. Clearly, code maintenance is not a ChatGPT core strength.
Implications
Obviously, this is a simple plugin. It’s roughly the size of the assignments I gave to my first year programming students when I taught at UC Berkeley. It doesn’t come close to the complexity of the much, much larger open source WordPress plugins I maintain for 50,000+ users.
Also: The developer role is changing radically. These figures show how
Last week, when I first used ChatGPT to build the quickie plugin for my wife and tweeted about it, correspondents on my socials pushed back. Here were some of their concerns:
Is it evil? One person was concerned that the AI would embed malicious (or at least promotional) information in the plugin and a non-programmer user would never know. But the fact is, if you’re not a coder and can’t read code, even if you contract with another human, you don’t really know what’s inside. It all comes down to either trusting reputation, or getting someone you do trust to look through the code. In the case of the code produced in my experiment, it was clean.
Is it the best it can be? Here again, folks were holding up the AI’s code to a different standard than even human coders. I’m a good programmer, but my code has bugs. It’s not the best it can be…at least not at first. But with humans, code gets better over time. I’m not sure if an AI can take existing code, improve it, debug it, and enhance it. However, sometimes things just need to be functional. It doesn’t always matter if they’re the best of the best. Good enough is often good enough. And it generated code that was good enough.
Will it reduce the number of human programming gigs? Almost undoubtedly. I hate to see a machine take any person’s job (especially if it’s one I might want). AI is definitely an option for quick and easy projects, whether that’s writing or programming. People’s paychecks will be impacted, no doubt.
I’ve been studying AI for decades. I did a thesis on AI. But even with all that background, this surge in high-quality generative AI has been startling to me. That said, what we’re looking at now is the “good enough” level of productivity. Unfortunately, that’s what many clients demand.
But — at least for now — ChatGPT and its friends can’t write super in-depth analysis articles like this, because they reflect opinions, anecdotes, and years of experience. And while they could probably write subroutines and functions for larger coding projects, they’re just not able to write major coding projects.
For example, I’ve had to have 20-30 meetings over the last year with a major API provider to integrate their service into mine. Most of those meetings mixed business issues with technical requirements and licensing policies. I defy any AI to put up with, understand the nuances of, and meet the partner requirements of that kind of bureaucratic situation, and then be able to produce code modules everyone can agree upon.
So, yes, I’m a bit freaked by how good the plugin was that I “made” for my wife. But the AI has a long way to go before it’s taking work from experienced developers and writers — as long as clients want the kind of work experienced developers and writers produce. And that, my friends, is something I do worry about.
You can follow my day-to-day project updates on social media. Be sure to follow me on Twitter at @DavidGewirtz, on Facebook at Facebook.com/DavidGewirtz, on Instagram at Instagram.com/DavidGewirtz, and on YouTube at YouTube.com/DavidGewirtzTV.
For all the latest Technology News Click Here
For the latest news and updates, follow us on Google News.