Navigating the New Era of AI-Assisted Code Generation in WordPress

The world is learning new ways of moving faster with the help of AI, as the increased availability of the technology is poised to transform the way humans work. Generitive AI is decades old but recent advances and new tools like DALL-E (launched in January 2021) have made AI more accessible to the public.

When ChatGPT arrived in November 2022, it sparked an explosion of tools built to extend its capabilities to nearly every aspect of work. Conversational AI tools can now handle a myriad of mundane tasks like updating your resume, reading and summarizing PDFs, and creating slides for presentations. Yesterday Google announced it is testing Bard, its AI chatbot rival to ChatGPT and Bing AI. In the fast-moving world of companies innovating with AI, GitHub also announced Copilot X, which is powered by GPT-4 and adds Copilot to pull requests, docs, and the command line and introduces chat and voice features for Copilot.

WordPress plugin developers are adopting AI-powered tech and building it into their products, such as RankMath’s AI-generated suggestions for creating SEO-friendly content, WordPress.com’s experimental blocks for AI-generated images and content, and a Setary’s plugin that uses AI to write and bulk edit WooCommerce product descriptions. The wpfrontpage site is tracking these plugins but WordPress.org also lists dozens of plugins with AI, many of them created to write content or generate images.

In addition to adding AI to plugins, developers have attempted to have ChatGPT build plugins for them, with varying degrees of success:

So far developers report having more success with ChatGPT than Bard. In some cases the creation process is incomplete and requires some expertise to ensure the plugin will work, but it’s also opening up the world of plugin development to those who would not be able to create one without hiring a developer.

https://twitter.com/amado_serna/status/1637170105363886081

WordPress developers who want to share their AI-assisted creations with the community have also started submitting them to WordPress.org.

After receiving a string of violations, WordPress’ Plugin Team is warning developers that code submitted to the official directory must be GPL compatible.

“There is no guideline AGAINST using generated code,” Plugin Review Team rep Mika Epstein said.

“You’re welcome to use whatever tool you want to build plugins. That said, you are 100% responsible for that code if you chose to host it here…

“But the important bit here is that it means if ChatGPT, for example, built your plugin, you have to verify that all the code used is GPL compatible. Just like you are expected to validate licenses on libraries and code-snippets, everything in your plugin has to be GPL compatible. Should we determine that your code is a copy of someone else’s or includes code from non-GPL plugins, your submission will be rejected and any live plugins will be closed.”

Epstein cited an example where a developer built a “scroll to top” plugin with code that was copied from another, existing plugin hosted on WordPress.org. It was submitted five times and rejected every time.

“Yes it’s fine to fork code,” Epstein said. “You have to credit them, however, and that’s something those AIs have been pretty bad at doing.” 

Commenters noted that autocomplete in modern IDEs work in a similar way, as well as snippets. These types of tools can enhance productivity but prospective plugin developers who may not be as informed about software licensing, should stay away from wholesale copying another’s work without crediting them. This may require doing some extra research on the code that AI spits out.

In this new era of AI-assisted creation, we have essentially hitched our wagon to a star, as Ralph Waldo Emerson described in his essay on Civilization in 1870:

Now that is the wisdom of a man, in every instance of his labor, to hitch his wagon to a star,’ and see his chore done by the gods themselves. That is the way we are strong, by borrowing the might of the elements. The forces of steam, gravity, galvanism, light, magnets, wind, fire, serve us day by day and cost us nothing.

Ralph Waldo Emerson, Civilization

That decade brought humanity inventions like the phonograph, telephone, and the incandescent light bulb, followed by the automobile in the next decade. Emerson’s essay explores man’s relationship to technology where principles—”justice, love, freedom, knowledge, utility”— are the guiding light and accelerant of technology’s impact.

The GPL is one of those principles for the WordPress community, which has enabled its uncommon growth and its wildly successful ecosystem. There are still a lot of grey areas when it comes to licensing and the code generated by AI. Developers would do well to use AI-generated code for inspiration and give credit where they can.

Web developer Mark Praschan created his first plugin for WordPress.org using ChatGPT. He used the free version, gave it a few prompts describing what he wanted it to do, and ChatGPT produced a functional plugin.

NorthStar allows users to display a message in the WordPress admin bar with settings to customize it along with the text and background colors.

“The first version worked great,” Praschan said. “I made a few small aesthetic improvements to the settings page and the display of the message, but we were already 95% of the way there!”

Praschan also had ChatGPT design an ASCII Art logo for the plugin. It required a few back-and-forth prompts but took just a few minutes before it was ready to be copied and pasted into Photoshop.

The plugin did not pass the code review on the first try for two reasons that Praschan shared on Twitter:

  • Issue # 1: Variables and options must be escaped when echo’d. There were 2 instances of not “escaping late”
  • Issue # 2: Generic function/class/define/namespace names. One function was missing the “northstar_” prefix.

“How did I fix it? I made ChatGPT do it, of course,” Praschan said. “I copy/pasted the problems and a few snippets of my code and it spat out the fixed code.”

There are more of these plugins coming – where a person need only dream up the idea and prompt their chosen AI tool for the code. These will more than likely be simple plugins for the time being, but it’s not too early to establish some best practices for using code generators. WordPress is navigating new territory where anyone can create a plugin with a dash of creative prompts and very little code experience.

5

5 responses to “Navigating the New Era of AI-Assisted Code Generation in WordPress”

  1. We’ve really opened up a can of worms here. I used ChatGPT to write a plugin. But to be honest, I hadn’t thought about where it mined the code from. I was simply happy that it included some sanitized output.

    How can we verify that we’re not simply copying someone else’s plugin? That’s going to be difficult.

    And the quality and/or security of the code? That’s a whole other ball of wax. You might need to be a proficient programmer to fully understand what you’ve built.

  2. Interesting for small plugins but ChatGTP was “not able” to build me a more sophisticated plugin (I gave it a three line prompt). It returned a list of suggestions instead, which included shortcodes, widgets and responsive design. It seemed to access too much learning from 2012 in this case.

    Things are getting “scary” fast, though. AI assistance within code editors is exciting for developers. Midjourney blows my mind. And Siri can finally direct me to the local Wich Which.

  3. This is far less revolutionary than it seems

    I’ve yet to see LLMs build anything complex or original (yet alone both) and so far I’m unconvinced then can (yet).

    Moreover how can you verify the quality of code

    LLMs do exce at doing simple things where existing or related solutions already exist. However there are already multiple solutions most simple tasks in the repository already (although the quality of the solutions vary enormously).

  4. We can imagine the headlines in six months when another popular site or plug-in is hacked, when both the author and the generator and the webmaster don’t understand the code, and can’t review it for security weaknesses,

    The current tools are proof of concept creators, but please be careful not to assume production ready code.

    If you want a code review done hit up an engineer.

  5. I remember this quote from Jurassic Park: “Your scientists were so preoccupied with whether they could, they didn’t stop to think if they should.”

    That’s mostly how I see the recent development of what people call “AI” …and not because Cylons or Terminators will destroy the human race. We tend to think today that if something is done faster, it is better because we can generate more profit. As long as we keep thinking this way, bad things will continue to happen and I think we will continue to degenerate as people. There is little regard for diligence, hard work and creativity when money is on the line, regardless of the way it can be generated. And people are being taught to appreciate things that are lower quality, why paying more. I believe AI will be heavily used for providing low-quality, unoriginal, repetitive products in many fields. Ubisoft has already announced AI will prepare some dialogues for their next video games. Companies use it to generate low-effort written content, sometimes with misleading information. We’re not getting better, we’re getting lazier with this, and even less demanding.

Newsletter

Subscribe Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.