Improve Site Navigation and WordPress SEO with New SmartCrawl Breadcrumbs

Can ChatGPT Build a Useful WordPress Plugin That Actually Works?

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

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…

ChatGPT - WordPress plugin creation prompt.
This immediate will certainly kick ChatGPT’s WordPress plugin growth tyres.

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…

ChatGPT response to WordPress plugin development prompt.
Mmm…perhaps my first try at creating a WordPress plugin was a tad too formidable!

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 code
To somebody who is aware of ‘zip’ about coding, the above code snippet certain seems to be spectacular!

ChatGPT additionally output all the extra code required to finish the following steps.

ChatGPT - WordPress plugin development prompt.
Lacking coding expertise, I relied on ChatGPT to information me via every step of the plugin growth course of.

And it apologized for my lack of coding data and expertise…

ChatGPT- prompt
This is what occurs when a dummy asks ChatGPT to create a dummy plugin.

It additionally guided me with step-by-step directions, identical to it had promised…

Screenshot of ChatGPT response.
I’m simply gonna let ChatGPT do all of the heavy lifting right here…

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.

The Hub - Create A New Site
Let’s spin up a new take a look at web site utilizing 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.

New WordPress site.
A model new WordPress web site with not a lot to see simply but.

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.

The Hub - File Manager
I might have used the Plugin uploader, however The Hub’s File Manager works simply as nicely!

With the plugin file uploaded, I activated it contained in the Plugins display.

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

And…I bought a deadly error!

Plugins screen - Fatal error message.
What an anticlimax…the bottom level of my WordPress plugin growth profession!

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.

Screenshot of ChatGPT prompt and response.
Why couldn’t it simply have given me the whole copy and paste code the primary time?

There was a lot of code to output, so each time issues got here to a standstill, I instructed ChatGPT to proceed the method.

Screenshot of ChatGPT prompt and response.
ChatGPT generally simply wants a little mild encouragement to maintain going.

I repeated this course of a number of occasions.

Screenshot of ChatGPT response.
Feels like ChatGPT and I are like an outdated married couple now…

Finally, the whole code was output. ChatGPT even offered some useful data on the finish of the method.

Screenshot of ChatGPT response.
After ready a complete 2 minutes…ChatGPT lastly output the entire plugin code!

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…

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

And a settings display with a lot of fancy bins and fields.

Dummy Content Generator WordPress plugin settings screen.
Looks spectacular…however will it work?

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.

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

And…completely nothing occurred!

WordPress Posts Table showing a sinlge
The latest lowest level of my WordPress plugin growth profession…a plugin that does nothing!

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 name dummy_content_generator_get_random_paragraph for each paragraph it tries to generate. The downside is that there isn’t a dummy_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…

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

And right here’s the listing of instructed plugins ChatGPT replied with…

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

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 prompt to generate code for a WordPress plugin that duplicates content.
This is what a license to print cash seems to be like!

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.

ChatGPT instructions.
The code not solely comes with directions, however ChatGPT even says “Please”!

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.

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

I additionally created a dummy put up to check the plugin with…

WordPress test post.
Can the plugin duplicate this tacky put up? Let’s discover out!

Here are the put up’s menu choices earlier than activating the plugin…

WordPress Posts table with single post entry.
A default put up with default choices.

Let’s go and activate the plugin…

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

Success! The plugin activated.

WordPress Plugins screen - Plugin activated message.
A gratuitous screenshot proving that the plugin efficiently 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…

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

A replica put up has been created…

An example of a duplicated WordPress post.
A replica of the unique put up.

Here’s the desk of posts displaying entries for the unique and duplicated put up.

WordPress Posts table with original post and duplicated post.
The unique put up and its cloned model.

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

Check Also

UK Publishers File £13.6 Billion Lawsuit Against Google Alleging Market Abuse

Gutenberg 15.8 Adds Pages Menu to Site Editor, Revisions UI to Global Styles

Gutenberg 15.8 was launched with some thrilling options that had been included within the tentative …