Can AI flip non-coders into professional WordPress plugin builders? To discover out, we requested ChatGPT to construct a customized WordPress plugin from scratch after which had our crack group of builders study the code…
AI is the world’s hottest two-letter phrase proper now. With all of the latest information headlines about whether or not AI will take our jobs away, we wished to know… can ChatGPT really develop a useful and helpful WordPress plugin with out having to put in writing code from scratch? And does the plugin meet finest coding practices?
Fortunately, WPMU DEV builds among the most strong WordPress plugins on this planet, so we’ve loads of knowledgeable WordPress plugin builders who can put ChatGPT to the take a look at.
In reality, for those who take a stroll round our firm’s digital corridors, you possibly can’t assist however stumble upon WordPress coders and builders. It appears everybody round right here can take a look at a WordPress plugin and see PHP the way in which Neo sees the Matrix’s digital rain code.
Everyone, that’s …besides me!
I’m simply a weblog author with no coding expertise and a burning want so as to add “prompt engineer” to my resumé.
So, on this put up, we’ll discover easy methods to leverage the ability of ChatGPT to construct a easy customized WordPress plugin shortly and securely, even for those who lack intensive coding expertise.
We’ll do that by:
1) Asking ChatGPT to generate the code for a helpful plugin that we will take a look at, and
2) Running the code generated by ChatGPT previous our group {of professional} plugin builders to allow them to overview it and supply their sincere suggestions.
We’ll cowl the next:
- Exploring the Power of ChatGPT for WordPress Plugin Development
- Define Your Plugin’s Functionality
- Generate Code Snippets with ChatGPT
- Set Up Your Test Site
- Test Your Custom Plugin
- Feedback from Our Expert Plugin Developers
- Can ChatGPT Turn You Into a WordPress Plugin Developer?
Exploring the Power of ChatGPT for WordPress Plugin Development
One of the explanations WordPress is the world’s hottest content material administration system is the software program’s flexibility and extensibility to create websites that may do something and every part utilizing plugins.
While there are over 60,000 free WordPress plugins out there masking each sort of performance you possibly can think about, generally you could want a customized resolution to satisfy a shopper’s particular necessities.
If you’re not a WordPress plugin developer, then till lately, your solely choices have been to both turn into a WordPress plugin developer and learn to code a plugin from scratch or modify an current plugin’s code, or rent a WordPress developer to do that for you.
With the explosion of recent AI instruments and applied sciences, we now have a third possibility, which whereas not essentially promising to do issues higher, may also help you get issues completed cheaper and sooner (take a look at our latest article on ways in which ChatGPT may also help you as a WordPress developer).
ChatGPT, powered by OpenAI, is a complicated language mannequin able to producing human-like textual content primarily based on given prompts. It additionally claims to have the ability to help you within the technique of constructing customized WordPress plugins by offering code snippets, explanations, and even suggestions for finest practices.
So, we wished to seek out out for ourselves if we will leverage ChatGPT to speed up the WordPress plugin growth course of and make sure the safety of your plugins.
To do that, we’ll ask ChatGPT to construct us a easy, helpful, and useful plugin.
Define Your Plugin’s Functionality
Before utilizing ChatGPT to generate code, it’s essential to have a clear understanding of the performance you need your plugin to supply.
This begins by outlining the particular options, actions, or modifications you wish to obtain together with your plugin. This will then allow you to generate correct prompts for ChatGPT and be certain that your AI-generated code aligns together with your desired outcomes.
Generate Code Snippets with ChatGPT
To generate our code snippets utilizing ChatGPT, we’ll preserve issues easy (and free) and use the freely out there interface offered by OpenAI.
Take #1…
Note: My first try at utilizing ChatGPT to create a WordPress plugin from scratch was manner too formidable. I requested ChatGPT to construct me a easy WordPress time-travel dummy textual content producing plugin, utilizing the immediate beneath…
As somebody who spends a lot of time writing WordPress tutorials, I typically want dummy content material to check plugins, create screenshots, and so on.
So, I assumed it could be nice to mannequin my AI-generated dummy content material plugin on a plugin I typically use known as FakerPress.
ChatGPT instantly pushed again on my request and instructed me that creating a absolutely useful WordPress plugin with all of the options I described was past the scope of a single response.
However, it did supply to supply me with a fundamental template, information me on easy methods to implement among the options I discussed, and even gave me directions on easy methods to create a plugin listing and file…
At first, I assumed there was gentle on the finish of the tunnel. ChatGPT output code that appeared fairly spectacular to my untrained eyes and unskilled thoughts…
ChatGPT additionally output all the extra code required to finish the following steps.
And it apologized for my lack of coding data and expertise…
It additionally guided me with step-by-step directions, identical to it had promised…
I can’t actually describe what I felt seeing ChatGPT spit out the code, but it surely’s most likely just like what Bill Gates will need to have felt when he first held a set of floppy disks containing the working code for the Windows working system.
Set Up Your Test Site
With the plugin code generated, the following step was to arrange a dummy web site to check the plugin.
I shortly spun a new web site in The Hub.
Note: If you might be creating a plugin for an current web site, we suggest organising a native growth atmosphere or a staging web site to make sure that the plugin works as meant and doesn’t battle with different current plugins or themes on the location.
After drumming my fingers on my desk for a couple of minutes, my new WordPress web site was prepared.
With the take a look at web site arrange, the following step was to add the plugin and take a look at to ensure it really works.
Test Your Custom Plugin
I adopted ChatGPT’s directions and uploaded the plugin folder to the wp-content > plugins
listing of my take a look at web site utilizing The Hub’s file supervisor.
With the plugin file uploaded, I activated it contained in the Plugins display.
And…I bought a deadly error!
Assuming that perhaps I didn’t add the extra snippets that ChatGPT offered accurately, I went again and requested for all of the code to be offered as a single file that I might merely copy and paste to overwrite and replace the uploaded plugin file.
ChatGPT obliged and delivered me the whole code.
There was a lot of code to output, so each time issues got here to a standstill, I instructed ChatGPT to proceed the method.
I repeated this course of a number of occasions.
Finally, the whole code was output. ChatGPT even offered some useful data on the finish of the method.
I uploaded the plugin file with the brand new code to my take a look at web site, then jumped into the location’s admin space and activated the plugin.
It labored! Or so it appeared.
ChatGPT even gave the plugin its personal menu merchandise…
And a settings display with a lot of fancy bins and fields.
My first impression was “Wow…ChatGPT created the plugin and made its own decisions about some of the plugin settings and the user interface layout and design!”
But… “does the plugin work?”
I couldn’t see a discipline the place I might specify what number of posts or pages to create, so I merely ticked some bins, entered some values, and clicked on the “Save Changes” button to see what occurs.
And…completely nothing occurred!
My fancy-ass plugin was all make-believe, identical to a kind of youngsters’s playground spaceships that’s full of ineffective knobs you possibly can flip and buttons you possibly can press whereas pretending to be flying in outer area.
So, I reached out to certainly one of our builders through Slack and requested them to take a look at the plugin file.
Some of the feedback that got here again included the next:
- “The plugin tries to generate random content on each and every admin page load”
- “It calls a perform
dummy_content_generator_generate_content_paragraphs
which, in flip, makes an attempt to namedummy_content_generator_get_random_paragraph
for each paragraph it tries to generate. The downside is that there isn’t adummy_content_generator_get_random_paragraph
perform. - “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 forwards and backwards discussions , it was deemed that there was fairly a lot fallacious with the plugin, that it could take a lot of labor to repair it, they usually instructed I scrap the mission.
At this level, nonetheless, I used to be too invested in my mission to easily abandon every part and quit. Recalling Sir Winston Churchill’s well-known phrases (“Fetch me another brandy” “Never give in, never give in, never, never, never…”), I made a decision it was time for…
Take #2…
Ok, so my first try to get ChatGPT to construct a WordPress plugin from scratch was a dismal failure. This in itself offered some invaluable insights into ChatGPT’s means to carry out advanced coding duties (or, as somebody within the group put it, “you can’t code using ChatGPT without having extensive coding knowledge.”)
So, for “Take #2,” let’s reset and go once more with a less complicated plugin request.
Going again to the drafting board, a genius lightbulb second lit up my thoughts…why not ask ChatGPT to recommend concepts for easy WordPress plugins it might then generate the code for?
So, that’s what I did. Here’s the immediate I promptly engineered…
And right here’s the listing of instructed plugins ChatGPT replied with…
I favored the final suggestion, so I requested ChatGPT to generate the code for a useful content material duplicator plugin, and it instantly went to work.
ChatGPT generated the next code for the plugin within the blink of a watch:
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 put up perform 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' ) ) { $put up = 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 $worth ) { add_post_meta( $new_post_id, $key, $worth ); } } // Redirect to the duplicated put up wp_redirect( admin_url( 'put up.php?motion=edit&put up=' . $new_post_id ) ); exit; } } } } add_action( 'admin_post_content_duplicator_duplicate_post', 'content_duplicator_duplicate_post' );
It even offered a set of directions after producing the code.
I then went again to my take a look at web site and uploaded the brand new plugin file to the wp-content > plugins
listing.
I additionally created a dummy put up to check the plugin with…
Here are the put up’s menu choices earlier than activating the plugin…
Let’s go and activate the plugin…
Success! The plugin activated.
Now, let’s see if the plugin really works.
Here’s my take a look at put up once more. Note that the plugin has added a new “Duplicate” merchandise to the menu after being activated.
Let’s click on on “Duplicate” and see what occurs…
A replica put up has been created…
Here’s the desk of posts displaying entries for the unique and duplicated put up.
I’m certain that with higher immediate engineering and a few code tweaking, the plugin might have been considerably improved. For instance, I would like if the plugin set the put up standing of the newly-duplicated put up to ‘draft’ as an alternative of publishing it, however ChatGPT delivered a easy WordPress plugin that labored. It was fundamental, but it surely did the job.
All I wanted to do now was to ask somebody who codes WordPress plugins for a dwelling to scrutinize the code and share how they felt about utilizing a device like ChatGPT to code plugins.
Feedback from Our Expert Plugin Developers
Shortly after importing the plugin to certainly one of our testing channels, I bought pinged from certainly one of our builders. Here are among the key factors offered of their suggestions:
- “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 used to be to be super-nitpicky about this, I’d additionally point out that it’s not L10n-ready – there gained’t be an choice to translate this plugin. But, that’s simply being very nitpicky – I don’t actually assume, nor would I anticipate, a prompt-generated plugin to be generic sufficient to be needing one thing like that in any respect. To me, it’s extra of a “very specific problem domain” sort of a factor, together with the language used. At the top of the day, it does do what it says it can, which may be very good.”
In addition to analyzing the WordPress plugin code generated by ChatGPT and offering suggestions as proven above, our builders additionally agreed with the next key factors after assessing ChatGPT’s present capabilities to generate code:
1 – It’s essential to train warning and never blindly settle for ChatGPT-generated code as right.
- ChatGPT can present solutions, but it surely’s as much as the consumer to evaluate whether or not the reply is right or not.
- There is a threat of receiving incorrect or nonsensical solutions from ChatGPT, each apparent and refined.
- It’s essential to train warning and never blindly settle for the generated code as right.
- ChatGPT’s output ought to be handled as autocomplete, making life simpler however requiring warning and verification.
The means to discern good code from dangerous or nonsensical code, nonetheless, implies that…
2 – Users ought to have adequate data and understanding of WordPress plugin growth to judge and modify the generated code as wanted.
- ChatGPT may also help simplify and expedite the method of constructing easy customized WordPress plugins, generate code snippets, and supply explanations. Anything extra advanced, nonetheless, requires plugin growth expertise and coding expertise.
- Using ChatGPT with out adequate data can result in unfavorable penalties or unreliable code.
- Relying solely on ChatGPT with out crucial considering is just like blindly copying the primary reply from Stack Overflow (Stack Overflow threads present extra context, a number of solutions, and suggestions from different customers, making it a extra dependable useful resource, however Stack Overflow threads are typically extra generic, whereas ChatGPT can present particular solutions to particular person queries).
3 – Utilizing different sources, similar to WordPress documentation, tutorials, and group boards, alongside ChatGPT can present a extra complete understanding of WordPress plugin growth.
- As you discover the chances of utilizing ChatGPT for WordPress plugin growth, it’s invaluable to have interaction with the WordPress group. Share your experiences, ask for suggestions, and search steering from skilled builders. Participating in boards, attending WordPress meetups, or becoming a member of on-line communities can present invaluable insights and allow you to refine your plugin growth course of.
- Additionally, take into account following WordPress safety finest practices to safeguard your web site from potential vulnerabilities. ChatGPT can present suggestions on safety measures you possibly can implement to guard your plugin.
- It’s additionally important to take care of a clear understanding of your required performance and completely overview and take a look at the generated code and safe your customized plugins earlier than deploying them to a manufacturing atmosphere.
Can ChatGPT Turn You Into a WordPress Plugin Developer?
We’ve explored how one can make the most of ChatGPT to construct easy customized WordPress plugins shortly and securely, even when you have restricted coding expertise.
Beyond the core performance of your plugin, you can too leverage ChatGPT to generate code for customized consumer interfaces. With its means to know prompts and generate HTML, CSS, and JavaScript snippets, you possibly can create intuitive admin interfaces, front-end parts, and interactive components that may improve the consumer expertise and let you ship a polished closing product.
By using the language mannequin’s capabilities, you possibly can generate code snippets, optimize performance, and create user-friendly interfaces. However, it’s essential to know the generated code, overview and refine it, and completely take a look at your customized plugins earlier than deploying them to your dwell web site.
The generated code can also require changes to align with coding requirements, naming conventions, or particular mission necessities. This requires a certain quantity of coding data and expertise, as does optimizing the code and making certain it follows WordPress coding pointers for higher maintainability.
The backside line: AI-powered instruments like ChatGP can streamline your workflow, increase productiveness, and unlock new prospects. While ChatGPT is a highly effective and invaluable device to have in your arsenal, AI gained’t exchange expert coders any time quickly.
Interested in Developing WordPress plugins?
Check out a few of our tutorials and articles on WordPress plugin growth:
- Getting Started with WordPress Plugin Development
- A Quick and In-Depth Guide to WordPress Hooks
- Creating WordPress Plugins in An Object Oriented Way