Can AI turn non-coders into pro WordPress plugin developers? To find out, we asked ChatGPT to build a custom WordPress plugin from scratch and then had our crack team of developers examine the code…

AI is the world’s most popular two-letter word right now. With all the recent news headlines about whether AI will take our jobs away, we wanted to know… can ChatGPT actually develop a functional and useful WordPress plugin without having to write code from scratch? And does the plugin meet best coding practices?

Fortunately, WPMU DEV builds some of the most robust WordPress plugins in the world, so we have plenty of expert WordPress plugin developers who can put ChatGPT to the test.

In fact, if you take a stroll around our company’s virtual corridors, you can’t help but bump into WordPress coders and developers. It seems everyone around here can look at a WordPress plugin and see PHP the way Neo sees the Matrix’s digital rain code.

Matrix code
What PHP code looks like to experienced WordPress plugin developers. Source: Giphy.com

Everyone, that is …except me!

I’m just a blog writer with no coding skills and a burning desire to add “prompt engineer” to my CV.

So, in this post, we’ll explore how to leverage the power of ChatGPT to build a simple custom WordPress plugin quickly and securely, even if you lack extensive coding skills.

We’ll do this by:

1) Asking ChatGPT to generate the code for a useful plugin that we can test, and

2) Running the code generated by ChatGPT past our team of professional plugin developers so they can review it and provide their honest feedback.

We’ll cover the following:

Step 1 – Define the Plugin’s Functionality

Before using ChatGPT to generate code, we need to have a clear understanding of the functionality we want our plugin to provide.

This starts by outlining the specific features, actions, or modifications we’ll want to achieve with our plugin. This will then help us generate accurate prompts for ChatGPT and ensure that our AI-generated code aligns with our desired outcomes.

Step 2 – Generate Code Snippets with ChatGPT

To generate our code snippets using ChatGPT, we’ll keep things simple (and free) and use the freely available interface provided by OpenAI.

Take #1…

Note: My first attempt at using ChatGPT to create a WordPress plugin from scratch was way too ambitious. I asked ChatGPT to build me a simple WordPress time-travel dummy text generating plugin, using the prompt below…

ChatGPT - WordPress plugin creation prompt.
This prompt will surely kick ChatGPT’s WordPress plugin development tyres.

As someone who spends a lot of time writing WordPress tutorials, I often need dummy content to test plugins, create screenshots, etc.

So, I thought it would be great to model my AI-generated dummy content plugin on a plugin I often use called FakerPress.

ChatGPT pushed back on my request and let me know that creating a fully functional WordPress plugin with all the features I requested was beyond the scope of a single response.

However, it did offer to provide me with a basic template, guide me on how to implement some of the features I mentioned, and even gave me instructions on how to create a plugin directory and file…

ChatGPT response to WordPress plugin development prompt.
Mmm…maybe my first attempt at creating a WordPress plugin was too ambitious!

At first, ChatGPT output code that looked quite impressive…

ChatGPT code
To someone who knows ‘zip’ about coding, the above code snippet sure looks impressive!

ChatGPT also output all the additional code required to complete the next steps.

ChatGPT - WordPress plugin development prompt.
Lacking coding skills, I relied on ChatGPT to guide me through each step of the plugin development process.

With the plugin code output, the next step was to upload the plugin to my test site and test it to make sure it works.

Step 3 – Test The Custom Plugin

After uploading the folder containing the plugin code to the wp-content > plugins directory of my test site and activating it inside the Plugins screen…

Plugins screen - Dummy Content Generator activation menu link.
And now for the moment we’ve all been waiting for [drumroll]…

I got a fatal error!

Plugins screen - Fatal error message.
What an anticlimax…the lowest point of my WordPress plugin development career!

Assuming that maybe I didn’t add the additional snippets that ChatGPT provided correctly, I went back and asked for all the code to be provided as a single file that I could simply copy and paste to overwrite and update the uploaded plugin file…

Screenshot of ChatGPT prompt and response.
Why couldn’t it just have given me the entire copy and paste code the first time?

There was a lot of code to output, so whenever the process came to a standstill, I instructed ChatGPT to continue…

Screenshot of ChatGPT prompt and response.
ChatGPT sometimes just needs a little gentle encouragement to keep going.

After repeating this process several times, ChatGPT output the entire code and even provided some helpful information.

Screenshot of ChatGPT response.
After waiting a whole 2 minutes…ChatGPT finally output all of the plugin code!

I uploaded the plugin file with the new code to my test site, then jumped into the site’s admin area and activated the plugin.

It worked! Or, so it seemed.

ChatGPT gave the plugin its own menu item…

Dummy Content Generator WordPress plugin -created by ChatGPT
ChatGPT created all this!

And a settings screen with lots of fancy boxes and fields…

Dummy Content Generator WordPress plugin settings screen.
Looks impressive…but will it work?

But I couldn’t see a field to specify how many posts or pages to create, so I simply ticked some boxes, entered some values, and clicked on the “Save Changes” button to see what happens.

Dummy Content Generator WordPress plugin -created by ChatGPT
And now, for the moment of truth…

And…absolutely nothing happened!

WordPress Posts Table showing a sinlge
The newest lowest point of my WordPress plugin development career…a plugin that does nothing!

My fancy-ass plugin was all make-believe, just like one of those children’s playground spaceships that’s filled with useless knobs you can turn and buttons you can press while pretending to be flying in outer space.

So, I reached out to one of our developers via Slack and asked them to look at the plugin file.

Some of the comments that came back included the following:

  • “The plugin tries to generate random content on each and every admin page load”
  • “It calls a function dummy_content_generator_generate_content_paragraphs which, in turn, attempts to call dummy_content_generator_get_random_paragraph for every paragraph it tries to generate. The problem is that there is no dummy_content_generator_get_random_paragraph function.
  • “The page loads to a point, then it errors out because there’s more missing stuff”
  • “Other than all the mentioned issues, there’s no validation whatsoever, and no escaping of the output, which is terrible”
  • “In terms of having something as starting point, this is a very, very poor one. In terms of having a working plugin, this is nowhere near that”

After some back and forth discussions , it was deemed that there was quite a lot wrong with the plugin, that it would take a lot of work to fix it, and they suggested I scrap the project.

At this point, however, I was too invested in my mission to simply abandon everything and give up. Recalling Sir Winston Churchill’s famous words (“Fetch me another brandy” “Never give in, never give in, never, never, never…”), I decided it was time for…

Take #2…

Ok, so my first attempt to get ChatGPT to build a WordPress plugin from scratch was a dismal failure. This in itself provided some valuable insights into ChatGPT’s ability to perform complex coding tasks (or, as someone in the team put it, “you can’t code using ChatGPT without having extensive coding knowledge.”)

So, for “Take #2,” I decided to try again with a simpler plugin request.

Going back to the drawing board, a genius lightbulb moment lit up in my mind…why not ask ChatGPT to suggest ideas for simple WordPress plugins it could then generate the code for?

So, that’s what I did. Here’s the prompt I promptly engineered…

ChatGPT prompt for generating WordPress plugin ideas.
My genius prompt.

And here’s the list of suggested plugins ChatGPT replied with…

ChatGPT - List of WordPress plugin ideas.
The blueprint of my WordPress plugin empire.

I liked the last suggestion, so I asked ChatGPT to generate the code for a functional content duplicator plugin, and it immediately went to work.

ChatGPT prompt to generate code for a WordPress plugin that duplicates content.
This is what a license to print money looks like!

ChatGPT generated the following code for the plugin in the blink of an eye:

  ID ), 'content_duplicator_duplicate_post' ) . '" title="Duplicate this item" rel="permalink">Duplicate';      }      return $actions;  }  add_filter( 'post_row_actions', 'content_duplicator_add_duplicate_link', 10, 2 );    // Duplicate the post  function content_duplicator_duplicate_post() {      if ( isset( $_GET['post_id'] ) ) {          $post_id = absint( $_GET['post_id'] );            if ( current_user_can( 'edit_posts' ) && wp_verify_nonce( $_GET['_wpnonce'], 'content_duplicator_duplicate_post' ) ) {              $post = get_post( $post_id );                $args = array(                  'post_title' => $post->post_title . ' (Duplicate)',                  'post_content' => $post->post_content,                  'post_type' => $post->post_type,                  'post_status' => $post->post_status,                  'post_parent' => $post->post_parent,                  'post_author' => get_current_user_id(),              );                $new_post_id = wp_insert_post( $args );                if ( $new_post_id ) {                  // Duplicate meta fields                  $meta_fields = get_post_custom( $post_id );                  foreach ( $meta_fields as $key => $values ) {                      foreach ( $values as $value ) {                          add_post_meta( $new_post_id, $key, $value );                      }                  }                    // Redirect to the duplicated post                  wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );                  exit;              }          }      }  }  add_action( 'admin_post_content_duplicator_duplicate_post', 'content_duplicator_duplicate_post' );    

It even provided a set of instructions after generating the code.

ChatGPT instructions.
The code not only comes with instructions, but ChatGPT even says “Please”!

I then uploaded the new plugin file to the wp-content > plugins directory of my test site using The Hub’s file manager.

The Hub - File Manager
There’s a lot of action to unpack in this screenshot.

And created a dummy post to test the plugin with…

WordPress test post.
Did the plugin duplicate this cheesy post? Let’s find out!

Here are the post’s menu options before activating the plugin…

WordPress Posts table with single post entry.
A default post with default options.

After activating the plugin…

WordPress Plugins screen - Activate Content Duplicator
“Activate Content Duplicator” – Sounds like a line from a Star Trek movie.

Success!

WordPress Plugins screen - Plugin activated message.
A gratuitous screenshot proving that the plugin successfully activated.

The plugin activated. But did it actually work?

Here’s my test post again (note that the plugin added a new “Duplicate” item to the menu after activation). I then clicked on “Duplicate” to see what happens…

WordPress Posts Table - Post entry with a new Duplicate item.
ChatGPT even added a “Duplicate” menu item tooltip to the code!

And a duplicate post was created!

An example of a duplicated WordPress post.
A duplicate of the original post.

Here’s the table of posts showing entries for the original and duplicated post.

WordPress Posts table with original post and duplicated post.
The original post and its cloned version.

I’m sure that with better prompt engineering and some code tweaking, the plugin could have been significantly improved. For example, I would prefer if the plugin set the post status of the newly-duplicated post to ‘draft’ instead of publishing it, but ChatGPT delivered a simple WordPress plugin that worked. It was basic, but it did the job.

The last step was to ask someone who codes WordPress plugins for a living to scrutinize the code and get their opinion about using a tool like ChatGPT to code plugins.

Feedback from Our Expert Plugin Developers

Shortly after uploading the plugin to one of our testing channels, I got a ping from one of our developers. Here are some of the key points provided in their feedback:

  • “ChatGPT et al are decent at answering questions you already know the answer to.”
  • “I also used it in the past to build a simple plugin for me, but as long as I was giving more complex prompts, it started to mess things around, so eventually I manually debug the given code to work, cause else it’d take ages for it to actually debug it line by line.”
  • “Basically, it does what it says. However, it does what it says very literally. As in, it will duplicate a post and its corresponding postmeta (custom) fields. However, it doesn’t seem like it will propagate any taxonomies to the duplicated post (the plugin should copy and assign the same taxonomy terms, such as categories or tags, from the original post to the duplicated post).”
  • If I was to be super-nitpicky about this, I’d also mention that it’s not L10n-ready – there won’t be an option to translate this plugin. But, that’s just being very nitpicky – I don’t really think, nor would I expect, a prompt-generated plugin to be generic enough to be needing something like that at all. To me, it is more of a “very specific problem domain” kind of a thing, including the language used. At the end of the day, it does do what it says it will, which is very nice.”

In addition to examining the WordPress plugin code generated by ChatGPT and providing feedback as shown above, our developers also agreed with the following key points after assessing ChatGPT’s current capabilities to generate code:

1 – It’s important to exercise caution and not blindly accept ChatGPT-generated code as correct.

  • ChatGPT can provide answers, but it’s up to the user to assess whether the answer is correct or not.
  • There is a risk of receiving incorrect or nonsensical answers from ChatGPT, both obvious and subtle.
  • It’s important to exercise caution and not blindly accept the generated code as correct.
  • ChatGPT’s output should be treated as autocomplete, making life easier but requiring caution and verification.

The ability to discern good code from bad or nonsensical code, however, implies that…

2 – Users should have sufficient knowledge and understanding of WordPress plugin development to evaluate and modify the generated code as needed.

  • ChatGPT can help simplify and expedite the process of building simple custom WordPress plugins, generate code snippets, and provide explanations. Anything more complex, however, requires plugin development experience and coding skills.
  • Using ChatGPT without sufficient knowledge can lead to negative consequences or unreliable code.
  • Relying solely on ChatGPT without critical thinking is similar to blindly copying the first answer from Stack Overflow (Stack Overflow threads provide more context, multiple answers, and feedback from other users, making it a more reliable resource, but Stack Overflow threads tend to be more generic, whereas ChatGPT can provide specific answers to individual queries).

3 – Utilizing other resources, such as WordPress documentation, tutorials, and community forums, alongside ChatGPT can provide a more comprehensive understanding of WordPress plugin development.

  • As you explore the possibilities of using ChatGPT for WordPress plugin development, it’s valuable to engage with the WordPress community. Share your experiences, ask for feedback, and seek guidance from experienced developers. Participating in forums, attending WordPress meetups, or joining online communities can provide valuable insights and help you refine your plugin development process.
  • Additionally, consider following WordPress security best practices to safeguard your website from potential vulnerabilities. ChatGPT can provide recommendations on security measures you can implement to protect your plugin.
  • It’s also essential to maintain a clear understanding of your desired functionality and thoroughly review and test the generated code and secure your custom plugins before deploying them to a production environment.

Can ChatGPT Turn You Into a WordPress Plugin Developer?

In this article, we’ve explored how you can utilize ChatGPT to build simple custom WordPress plugins, even if you have limited coding experience.

In other articles, we’ve seen that AI-powered tools like ChatGP can streamline your workflow, boost productivity, and unlock new possibilities (check out our recent article on ways that ChatGPT can help you as a WordPress developer).

While there are over 60,000 free WordPress plugins available covering every type of functionality you can imagine, sometimes you may need a custom solution to meet a client’s specific requirements.

Beyond the core functionality of your plugin, you can also leverage ChatGPT to generate code for custom user interfaces. With its ability to understand prompts and generate HTML, CSS, and JavaScript snippets, you can create intuitive admin interfaces, front-end components, and interactive elements that will enhance the user experience and allow you to deliver a polished final product.

By utilizing the language model’s capabilities, you can generate code snippets, optimize functionality, and create user-friendly interfaces. However, it’s crucial to understand the generated code, review and refine it, and thoroughly test your custom plugins before deploying them to your live website.

The generated code may also require adjustments to align with coding standards, naming conventions, or specific project requirements. This requires a certain amount of coding knowledge and skills, as does optimizing the code and ensuring it follows WordPress coding guidelines for better maintainability.

The bottom line:

Here are my findings after trying to get ChatGPT to code me a plugin from scratch:

  1. I couldn’t have gotten this done without the help of our experienced developers.
  2. Using ChatGPT to generate code without coding knowledge is really challenging – it helps to know what you are doing 🙂
  3. While ChatGPT is a powerful and valuable tool, it doesn’t seem like AI will replace skilled coders any time soon.

Interested in Developing WordPress plugins?

Check out some of our tutorials and articles on WordPress plugin development:

Have you tried using AI tools like ChatGPT to build or customize a WordPress plugin? Share your thoughts and experiences in the comments below.