I asked ChatGPT to write a WordPress plugin. He did it, in less than 5 minutes


In fact, I’m more than scared. As an experiment, I asked ChatGPT to write a plugin that could save my wife time managing her website. I wrote a short description and ChatGPT wrote the whole thing: UI, logic, and everything.

In less than five minutes.

There are implications to all of this. We’ll come back to that in a few minutes. But first, let me tell you about the experience and what happened.

The need


line-randomizer-paypal-demo-wordpress-2023-01-31-23-41-28


ChatGPT wrote the plugin that generates this user interface. David Gewirtz/ZDNET

My wife runs a WordPress-based e-commerce site. She also runs a very active Facebook group for customers of her site. Each month, she draws up a list of random clients for marketing purposes. She’s been using a website so far that does a good job of randomizing rows. But that’s a bit more than it’s worth for exporting the list.

As I watched her struggle to retrieve the data, I thought it would be helpful to write a WordPress plugin that we could install on her site.

But writing even a very simple plugin would take me a few days, complete with UI elements and logic code, and I already have quite a few projects right now.

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

The result of the code proposed by WordPress is very dependent on your request


coded


The ChatGPT code (from my first, most basic prompt) / David Gewirtz/ZDNET

The key to getting ChatGPT to generate code correctly is a carefully written prompt. You must clearly describe what you need in order to get what you want. I started with a very basic sentence, just to see if it would work. Here is what I used:

Write a PHP 8 compatible WordPress plugin that provides a text input field into which a list of lines can be pasted and a button, which when pressed, randomizes the lines of the list and presents the results in a second input field. text entry.

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

When I showed it to my wife, she was impressed and surprised. But then, as usual, she asked for a new feature: making sure duplicate names aren’t side by side.

Yes because for her work she sometimes needs to include a person’s name in a list several times. But she doesn’t want these duplicates grouped together.

So I modified my initial prompt by adding the following additional conditions:

…ensure that two identical entries are not next to each other (unless there is no other option)… with the number of rows submitted and the number rows in the result identical to each other.

I included the phrase “unless there is no other option” and the requirement for an equal number of lines because I wanted to ensure that all names were included, and I was concerned that it only prioritizes the need to not have two names side by side rather than keeping all the names.

About 30 seconds later I had a new plugin. I uploaded this one to the server and tried it. It worked, but the end result included a few blank lines. So I added this condition to my previous request:

…without blank lines…

By this point, I had gotten used to the turnaround time, which was still under a minute. One more download and test, and again it worked.

I wanted one last feature, just to confirm the number of rows that had been processed. I wanted the plugin to display the number of rows for input and output fields. Here is the addition of this prompt:

…Beneath the first field, display text that says “Row to randomize: ” with the number of non-blank lines in the source field. Below the second field, display text that says “Rows that were randomized: ” along with the number of nonblank rows in the destination field.

It almost totally worked. Before execution, the output field displays a line. But after the randomization process is completed, it displays the exact number of rows in both fields.

The quality of the code generated by ChatGPT

Overall the quality of the code is clean. The program successfully generated the WordPress header block and wrote the dashboard UI for the plugin, as well as the plugin processing logic.

It placed my rows above the fields, whereas I had specified it below, but that’s not really a big deal. This is the same kind of error a customer might receive from a developer that would take some work to fix.

The code worked, but it didn’t incorporate all the best WordPress programming practices, especially on the secure part of the code.

Besides, ChatGPT also placed the plugin’s menu item in Settings. I probably would have placed it under Tools or given the function its own menu item. Since I didn’t specify all of this, I think ChatGPT made a default decision by placing the menu item there.

I added one last requirement to my prompt, asking the AI ​​to give the plugin a name:

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

Oddly, the AI ​​then gave me an entirely different plugin, which provides a shortcode rather than a dashboard interface. Let me explain this to non-WordPress users, because it’s interesting.

When you write a plugin for WordPress, you can make it available to visitors to the site (this is called the frontend) or available to those who log into the site’s dashboard (this is called the frontend). is the backend). In my initial instructions, I didn’t specify frontend or backend, but the AI ​​wrote what I wanted, i.e. a backend interface, a dashboard for the tool.

But in this last try, the AI ​​decided to write the plugin as a frontend tool, running it through a shortcode. In WordPress, you can embed a shortcode in a post and it will run a plugin’s code. The latest version the AI ​​produced gave me this shortcode, which would have presented the random lines feature to site visitors.

After that, ChatGPT sort of lost track. I wasn’t able to get any additional functionality added to the original plugin and ChatGPT just generated the shortcode version. It is therefore clear that code maintenance is not a strong point of ChatGPT.

The consequences that can be drawn from my experience of generating code with ChatGPT

Obviously, this is a simple plugin. It’s about the level of exercises I gave to my first-year programming students when I taught at university. It is nowhere near as complex as other WordPress plugins.

When I started talking about plugin creation by ChatGPT on social networks, I received many reactions. And I answer it here.


One person was concerned that the AI ​​would embed malicious (or at least promotional) information into the plugin and a non-programmer user would never know about it.

If you’re not a developer and can’t read code, even if you contract with another developer, you won’t really know what’s inside. Either trust the reputation or have someone you trust audit the code. And as for the code produced by ChatGPT, on this point, it was clean.


Is the ChatGPT code of very good quality?

I’m a good programmer, but my code has bugs, at least at first. And the nice thing about humans is that code improves over time. I’m not sure an AI can take existing code, improve it, debug it, and polish it. However, sometimes the code just needs to be functional. It is not always important that they are the best. What is good is often enough. And I have to say that ChatGPT generated code that was good enough.


Will it reduce the number of developer jobs?

Without a doubt. I hate to see a machine take over a person’s job. But AI is clearly an option for quick and easy projects, whether writing or programming. So jobs will jump, no doubt.

I’ve been studying AI for decades. I did a thesis on AI. But even with all that baggage, this surge of high-quality generative AI amazed me. That said, what we are currently seeing is a “good enough” level of productivity. And that is unfortunately what many customers demand.

But — at least for now — ChatGPT and its friends can’t write super in-depth review articles like this, because they reflect opinions, anecdotes, and years of experience. And while they could probably write subroutines and functions for larger development projects, they just can’t write code for larger projects.

For example, I had to hold 20-30 meetings last year with a major API vendor to integrate their service with mine. Most of these meetings mixed business issues with technical requirements and licensing policies. I challenge any AI to endure this torture, understand the nuances, and respond to partner demands. Then to be able to produce code modules that everyone agrees on.

So, yeah, I’m a little freaked out by the quality of the plugin I “made”. But AI still has a long way to go before it takes the work of experienced developers and writers. Well, as long as the clients want this kind of work. And that, my friends, is something that worries me even more.


Source: “ZDNet.com”





Source link -97