I asked ChatGPT to write a WordPress plugin I needed. Did it in less than 5 minutes

I asked ChatGPT to write a WordPress plugin I needed
OpenAI logo on a laptop surrounded by books

Photo: Nicolas Maeterlinck/Belga Mag/AFP via Getty Images

Not to put too fine a point on it, but I'm more than a little mad. As an experiment, I asked ChatGPT to write a plugin that could save my wife some time managing her site. I wrote a short description and ChatGPT wrote the whole thing – user interface, logic and all.

In less than five minutes.

Also: The best AI chatbots. ChatGPT and other fun alternatives to try

There are consequences. We'll get to that in a few minutes. First, let me introduce you to the experience and what happened.



ChatGPT wrote the plugin that creates this interface and handles the strings.

David Gewirtz/ZDNET

My wife owns a WordPress-based e-commerce site focused on a popular hobby. She also runs a very active Facebook group for her website customers. Each month, he randomizes a list of names and then does a virtual spinning wheel animation using that random list for a Facebook group. He was using a site on the internet that does a fair job of string randomization, but it pays a little more than it's worth to export the list.

Also: Can AI detectors save us from ChatGPT? I tried 3 online tools to find out

As I watched him struggle to return random names, I thought it might be helpful if I wrote a quick WordPress plugin that we could put on his site. He's on the panel every day so having that as a tool will be helpful.

But even a simple plugin would take a few days to write, in terms of UI elements and logic code, and I'm pretty swamped with projects these days.

And then I thought of ChatGPT. There have been discussions in the media about ChatGPT as a programming tool, so I decided to give it a try.

The hint

the code

Exit ChatGPT (my first, most basic tip)

David Gewirtz/ZDNET

The key to getting ChatGPT to do anything is a carefully written prompt. When programming, think like a manager or a customer. You need to clearly describe what you need to get what you want. I started with a very basic prompt just to see if it would work. Here is the tip I used.

Write a PHP 8-compatible WordPress application that provides a text input field into which a list of strings can be inserted and a button that, when clicked, randomizes the list's strings and displays the results in a second text input field.

Within a minute it generated the code you see on the right. I copied the generated code into a .php file, placed it in a folder with the same root name as the .php file, zipped it, and uploaded it to its server. It worked.

Also: Russian hackers are trying to break into ChatGPT, Check Point says

When I showed it to my wife, she was suitably impressed and surprised. But then the gears started turning and he asked for a new feature. make sure duplicate names are not side by side.

For his application, he sometimes has to list someone's name multiple times. But he didn't want those duplicates collected.

I modified my original prompt by adding the following additional conditions:

…ensures that no two identical records are next to each other (unless there is no other option)…are identical in number of rows represented and the resulting rows.

I included the phrase “unless there is no other option” and the identical count requirement because I wanted to make sure all names were included, and I was concerned that it prioritized not having two names next to each other. keeping all the names.

About 30 seconds later I had a new plugin. I uploaded that one to the server and tried it. It worked, but the output included some blank lines. So I added this condition to my previous tip.

without empty lines…

By now I was used to the turnaround time, which was always less than a minute. Another upload and test and again it worked.

Also: How to use ChatGPT?

I wanted one final feature, just to confirm how many rows were processed. I wanted the plugin to show the number of rows for input and output fields. Here's that quick addendum.

…below the first field, display the text that says “Randomization String.” with the number of blank lines in the source field. Under the second field, display the text that says “Strings that are randomized.

This mostly worked. Before the run, the output field shows one line. But when the randomization process is done, it shows the exact number of rows in both fields.

Code quality

Overall, code quality was clean. I present only the original answer, because otherwise it would not 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 put my summary rows above the fields though I noted below, not a huge complaint. It's the same error that a customer might get back from a human contractor and then require a little rework to fix.

Also: Can the Notion AI writing assistant write this article?

The coding worked, but it didn't incorporate all the WordPress programming best practices. For example, it did not clear user input. The WordPress community is strict about sanitizing input so that hackers can't fill in fields with data that could break the site, and this code had none of that.

As a later test, I instructed Ai to sanitize the input, and it did… up to a point. It sanitized the input inside the PHP function, but didn't sanitize the input when calling PHP inside the HTML. That would definitely leave a loophole for hackers.

It also dropped the plugin menu item Settings. I'd probably put it under Tools or give the feature its own menu item. Since I didn't specify where it should be called from, I think ChatGPT made an acceptable decision by placing the menu item where it was.

I added one final requirement to my prompt, asking that the AI ​​name the app.

Write a PHP 8 compatible WordPress plugin called “Robo Randomizer” that…

Oddly enough, the AI ​​gave me a completely different plugin, creating one that provides a shortcode rather than a console interface. Let me explain this to non-WordPress users, because it's interesting.

When you write something like this, you can make it available on the site to visitors (called the frontend) or to those who log into the site's dashboard to save the side (backend). In my initial set of prompts, I didn't specify frontend or backend, but AI wrote what I wanted, which was a backend, dashboard interface for the tool.

Also: OpenAI is hiring developers to code ChatGPT better

But this last time, he decided to write the plugin as a frontend tool, making it executable via a shortcode. In WordPress, you can put a shortcode (something like (randomize strings)) in a post and it will run the code in the plugin. The last version that the artificial intelligence produced gave me a shortcode that would allow the possibility of random lines to be presented to site visitors.

ChatGPT kind of lost the thread after that. I couldn't get the extra features that were added to the original app, and ChatGPT basically duplicated it by creating a shortcode version. Obviously, code maintenance is not ChatGPT's main strength.


Obviously, this is a simple plugin. That's about the size of the assignments I gave my first-year programming students when I taught at UC Berkeley. It doesn't come close to the complexity of the many, many larger open source WordPress plugins I maintain for 50,000+ users.

Also: With AI chatbots, are we looking for answers in all the wrong places?

Last week, when I first used ChatGPT to create a Quickie plugin for my wife and tweeted about it, my social media correspondents pushed back. Here are some of their concerns.

Is that bad? One person worried that the AI ​​would embed malicious (or at least advertising) information into the app and a non-developer user would never know. But the fact is, if you're not a coder and you can't read code, even if you're signing a contract with another human being, you don't really know what's inside. It all depends on whether you trust an authority or someone you trust to review the code. In the case of the generated code in my experiment, it was clean.

Is it the best it can be? Here again, humans were holding AI 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 could be…at least not at first. But with humans, code gets better over time. I'm not sure if AI can take existing code, improve it, debug it, and improve it. However, sometimes things just need to be functional. It doesn't always matter if they are 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 certainly. I hate to see a machine take a human's job (especially if it's something I might want). AI is definitely an option for quick and easy projects, be it writing or programming. Undoubtedly, people's wages will be affected.

I have studied AI for decades. I did a thesis on AI. But even against that backdrop, this rise in high-quality generative AI has been astounding to me. That said, what we're looking at now is a “good enough” level of productivity. Unfortunately, that's what many customers demand.

But – at least for now – ChatGPT and its friends can't write such super-in-depth analysis articles because they reflect opinions, anecdotes and years of experience. And while they could probably write subroutines and functions for larger coding projects, they simply aren't capable of writing basic coding projects.

Also: Google's ChatGPT competitor demo goes wrong

For example, I've had to have 20-30 meetings with a major API provider over the last year to integrate their service into mine. Most of those meetings mixed business issues with technical requirements and licensing policies. I'm opposed to any AI that has to adapt, understand the nuances, and meet the demands of partners in that kind of bureaucratic situation, and then be able to produce code modules that everyone can agree on.

So yeah, I'm a little surprised at how good the plugin I “made” for my wife was. But AI has a long way to go before it takes work away from experienced developers and writers as much as customers. wish the kind of work experienced developers and writers do. And that, my friends, is me to do to worry

You can follow my daily 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.

READ  Hackers Exploit WordPress Plugin Flaw to Deploy Godzilla

Leave a Reply

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