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:

ChatGPT Creates a Working WordPress Plugin – On the First Try

So, I Built a WordPress Plugin With ChatGPT

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

Unbelievable! How I Built 3 WordPress Plugins In 10 MINUTES using ChatGPT AI!

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

ChatGPT developed a WordPress plugin for us in just 3 minutes. Negotiating with a developer would have taken longer. https://t.co/lRqjWd9JPV
— Priit @ Amperly AI productivity (@amperlycom) March 16, 2023

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.