{"id":217072,"date":"2023-05-22T02:31:11","date_gmt":"2023-05-22T02:31:11","guid":{"rendered":"https:\/\/wpmudev.com\/blog\/?p=217072"},"modified":"2023-05-22T02:31:11","modified_gmt":"2023-05-22T02:31:11","slug":"wordpress-plugin-development-ai","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/wordpress-plugin-development-ai\/","title":{"rendered":"Can ChatGPT Build a Useful WordPress Plugin That Actually Works?"},"content":{"rendered":"<p>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&#8230;<\/p>\n<p>AI is the world&#8217;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&#8230; can <a href=\"https:\/\/chat.openai.com\/\" rel=\"noopener\" target=\"_blank\">ChatGPT<\/a> actually develop a functional and useful WordPress plugin without having to write code from scratch? And does the plugin meet best coding practices?<\/p>\n<p>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.<\/p>\n<p>In fact, if you take a stroll around our company&#8217;s virtual corridors, you can&#8217;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 <a href=\"https:\/\/matrix.fandom.com\/wiki\/Matrix_code\" rel=\"noopener\" target=\"_blank\">Neo sees the Matrix&#8217;s digital rain code<\/a>.<\/p>\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/v1.Y2lkPTc5MGI3NjExMjM1NTBiMTc4MDEwMmFlN2JlNTFiNmZmMGY5NDkyMzdiMmU1MmExYSZlcD12MV9pbnRlcm5hbF9naWZzX2dpZklkJmN0PWc\/A06UFEx8jxEwU\/giphy.gif\" alt=\"Matrix code\" width=\"480\" height=\"354\" \/><figcaption class=\"wp-caption-text\">What PHP code looks like to experienced WordPress plugin developers. Source: Giphy.com<\/figcaption><\/figure>\n<p>Everyone, that is &#8230;<em>except me! <\/em><\/p>\n<p>I&#8217;m just a blog writer with no coding skills and a burning desire to add &#8220;prompt engineer&#8221; to my CV.<\/p>\n<p>So, in this post, we&#8217;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.<\/p>\n<p>We&#8217;ll do this by:<\/p>\n<p>1) Asking ChatGPT to generate the code for a useful plugin that we can test, and<\/p>\n<p>2) Running the code generated by ChatGPT past our team of professional plugin developers so they can review it and provide their honest feedback.<\/p>\n<p>We&#8217;ll cover the following:<\/p>\n<ul>\n<li><a href=\"#plugin-functionality\">Step 1 &#8211; Define the Plugin&#8217;s Functionality<\/a><\/li>\n<li><a href=\"#generate-code-snippets\">Step 2 &#8211; Generate Code Snippets with ChatGPT<\/a><\/li>\n<li><a href=\"#test-plugin\">Step 3 &#8211; Test the Custom Plugin<\/a><\/li>\n<li><a href=\"#expert-feedback\">Feedback from Our Expert Plugin Developers<\/a><\/li>\n<li><a href=\"#final-say\">Can ChatGPT Turn You Into a WordPress Plugin Developer?<\/a><\/li>\n<\/ul>\n<h2 id=\"plugin-functionality\">Step 1 &#8211; Define the Plugin&#8217;s Functionality<\/h2>\n<p>Before using ChatGPT to generate code, we need to have a clear understanding of the functionality we want our plugin to provide.<\/p>\n<p>This starts by outlining the specific features, actions, or modifications we&#8217;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.<\/p>\n<h2 id=\"generate-code-snippets\">Step 2 &#8211; Generate Code Snippets with ChatGPT<\/h2>\n<p>To generate our code snippets using ChatGPT, we&#8217;ll keep things simple (and free) and use the freely available interface provided by OpenAI.<\/p>\n<h3>Take #1&#8230;<\/h3>\n<p><em>Note:<\/em> My first attempt at using ChatGPT to create a WordPress plugin from scratch was way too ambitious.\u00a0I asked ChatGPT to build me a simple WordPress <del>time-travel<\/del> <em>dummy text generating<\/em> plugin, using the prompt below&#8230;<\/p>\n<figure id=\"attachment_217082\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-217082\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/initial-prompt.png\" alt=\"ChatGPT - WordPress plugin creation prompt.\" width=\"971\" height=\"645\" \/><figcaption class=\"wp-caption-text\">This prompt will surely kick ChatGPT&#8217;s WordPress plugin development tyres.<\/figcaption><\/figure>\n<p>As someone who spends a lot of time writing WordPress tutorials, I often need dummy content to test plugins, create screenshots, etc.<\/p>\n<p>So, I thought it would be great to model my AI-generated dummy content plugin on a plugin I often use called <a href=\"https:\/\/wordpress.org\/plugins\/fakerpress\/\" rel=\"noopener\" target=\"_blank\">FakerPress<\/a>.<\/p>\n<p>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.<\/p>\n<p>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&#8230;<\/p>\n<figure id=\"attachment_217083\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217083 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/initial-response.png\" alt=\"ChatGPT response to WordPress plugin development prompt.\" width=\"1011\" height=\"699\" \/><figcaption class=\"wp-caption-text\">Mmm&#8230;maybe my first attempt at creating a WordPress plugin was too ambitious!<\/figcaption><\/figure>\n<p>At first, ChatGPT output code that looked quite impressive&#8230;<\/p>\n<figure id=\"attachment_217085\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217085 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/initial-code.png\" alt=\"ChatGPT code\" width=\"855\" height=\"2823\" \/><figcaption class=\"wp-caption-text\">To someone who knows &#8216;zip&#8217; about coding, the above code snippet sure looks impressive!<\/figcaption><\/figure>\n<p>ChatGPT also output all the additional code required to complete the next steps.<\/p>\n<figure id=\"attachment_217086\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-217086\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/next-step-prompt-02.png\" alt=\"ChatGPT - WordPress plugin development prompt.\" width=\"1045\" height=\"629\" \/><figcaption class=\"wp-caption-text\">Lacking coding skills, I relied on ChatGPT to guide me through each step of the plugin development process.<\/figcaption><\/figure>\n<p>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.<\/p>\n<h2 id=\"test-plugin\">Step 3 &#8211; Test The Custom Plugin<\/h2>\n<p>After uploading the folder containing the plugin code to the <code>wp-content &gt; plugins<\/code> directory of my test site and activating it inside the Plugins screen&#8230;<\/p>\n<p><figure id=\"attachment_217104\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217104 size-ratio-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/plugin-screen-1050x664.png\" alt=\"Plugins screen - Dummy Content Generator activation menu link.\" width=\"1050\" height=\"664\" \/><figcaption class=\"wp-caption-text\">And now for the moment we&#8217;ve all been waiting for [drumroll]&#8230;<\/figcaption><\/figure>I got a fatal error!<\/p>\n<figure id=\"attachment_217096\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217096 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/plugin-error-01.png\" alt=\"Plugins screen - Fatal error message.\" width=\"1016\" height=\"497\" \/><figcaption class=\"wp-caption-text\">What an anticlimax&#8230;the lowest point of my WordPress plugin development career!<\/figcaption><\/figure>\n<p>Assuming that maybe I didn&#8217;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&#8230;<\/p>\n<figure id=\"attachment_217094\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217094 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/next-step-response-05.png\" alt=\"Screenshot of ChatGPT prompt and response.\" width=\"925\" height=\"643\" \/><figcaption class=\"wp-caption-text\">Why couldn&#8217;t it just have given me the entire copy and paste code the first time?<\/figcaption><\/figure>\n<p>There was a lot of code to output, so whenever the process came to a standstill, I instructed ChatGPT to continue&#8230;<\/p>\n<figure id=\"attachment_217098\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217098 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/next-step-response-06.png\" alt=\"Screenshot of ChatGPT prompt and response.\" width=\"948\" height=\"644\" \/><figcaption class=\"wp-caption-text\">ChatGPT sometimes just needs a little gentle encouragement to keep going.<\/figcaption><\/figure>\n<p>After repeating this process several times, ChatGPT output the entire code and even provided some helpful information.<\/p>\n<div class=\"mceTemp\"><\/div>\n<figure id=\"attachment_217100\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217100 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/next-step-response-08.png\" alt=\"Screenshot of ChatGPT response.\" width=\"884\" height=\"648\" \/><figcaption class=\"wp-caption-text\">After waiting a whole 2 minutes&#8230;ChatGPT finally output all of the plugin code!<\/figcaption><\/figure>\n<p>I uploaded the plugin file with the new code to my test site, then jumped into the site&#8217;s admin area and activated the plugin.<\/p>\n<p>It worked! Or, so it seemed.<\/p>\n<p>ChatGPT gave the plugin its own menu item&#8230;<\/p>\n<figure id=\"attachment_217105\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217105 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/plugin-menu.png\" alt=\"Dummy Content Generator WordPress plugin -created by ChatGPT\" width=\"830\" height=\"912\" \/><figcaption class=\"wp-caption-text\">ChatGPT created all this!<\/figcaption><\/figure>\n<p>And a settings screen with lots of fancy boxes and fields&#8230;<\/p>\n<figure id=\"attachment_217106\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217106 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/plugin-settings.png\" alt=\"Dummy Content Generator WordPress plugin settings screen.\" width=\"625\" height=\"1269\" \/><figcaption class=\"wp-caption-text\">Looks impressive&#8230;but will it work?<\/figcaption><\/figure>\n<p>But I couldn&#8217;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 &#8220;Save Changes&#8221; button to see what happens.<\/p>\n<figure id=\"attachment_217107\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217107 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/testing-plugin.png\" alt=\"Dummy Content Generator WordPress plugin -created by ChatGPT\" width=\"616\" height=\"1254\" \/><figcaption class=\"wp-caption-text\">And now, for the moment of truth&#8230;<\/figcaption><\/figure>\n<p>And&#8230;absolutely nothing happened!<\/p>\n<figure id=\"attachment_217108\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217108 size-ratio-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/no-new-posts-1050x417.png\" alt=\"WordPress Posts Table showing a sinlge &quot;Hello world&quot; post.\" width=\"1050\" height=\"417\" \/><figcaption class=\"wp-caption-text\">The newest lowest point of my WordPress plugin development career&#8230;a plugin that does nothing!<\/figcaption><\/figure>\n<p>My fancy-ass plugin was all make-believe, just like one of those children&#8217;s playground spaceships that&#8217;s filled with useless knobs you can turn and buttons you can press while pretending to be flying in outer space.<\/p>\n<p>So, I reached out to one of our developers via Slack and asked them to look at the plugin file.<\/p>\n<p>Some of the comments that came back included the following:<\/p>\n<ul>\n<li>&#8220;The plugin tries to generate random content on each and every admin page load&#8221;<\/li>\n<li>&#8220;It calls a function <code>dummy_content_generator_generate_content_paragraphs<\/code> which, in turn, attempts to call <code>dummy_content_generator_get_random_paragraph<\/code> for every paragraph it tries to generate. The problem is that there is no <code>dummy_content_generator_get_random_paragraph<\/code> function.<\/li>\n<li>&#8220;The page loads to a point, then it errors out because there&#8217;s more missing stuff&#8221;<\/li>\n<li>&#8220;Other than all the mentioned issues, there&#8217;s no validation whatsoever, and no escaping of the output, which is terrible&#8221;<\/li>\n<li>&#8220;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&#8221;<\/li>\n<\/ul>\n<p>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.<\/p>\n<p>At this point, however, I was too invested in my mission to simply abandon everything and give up. Recalling Sir Winston Churchill&#8217;s famous words (<del>&#8220;Fetch me another brandy&#8221;<\/del> &#8220;Never give in, never give in, never, never, never&#8230;&#8221;), I decided it was time for&#8230;<\/p>\n<h3>Take #2&#8230;<\/h3>\n<p>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&#8217;s ability to perform complex coding tasks (or, as someone in the team put it, &#8220;you can\u2019t code using ChatGPT without having extensive coding knowledge.&#8221;)<\/p>\n<p>So, for &#8220;Take #2,&#8221; I decided to try again with a simpler plugin request.<\/p>\n<p>Going back to the drawing board, a genius lightbulb moment lit up in my mind&#8230;why not ask ChatGPT to suggest ideas for simple WordPress plugins it could then generate the code for?<\/p>\n<p>So, that&#8217;s what I did. Here&#8217;s the prompt I promptly engineered&#8230;<\/p>\n<figure id=\"attachment_217127\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217127 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/01-initial-prompt.png\" alt=\"ChatGPT prompt for generating WordPress plugin ideas.\" width=\"919\" height=\"113\" \/><figcaption class=\"wp-caption-text\">My genius prompt.<\/figcaption><\/figure>\n<p>And here&#8217;s the list of suggested plugins ChatGPT replied with&#8230;<\/p>\n<figure id=\"attachment_217128\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217128 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/02-plugin-ideas.png\" alt=\"ChatGPT - List of WordPress plugin ideas.\" width=\"914\" height=\"1980\" \/><figcaption class=\"wp-caption-text\">The blueprint of my WordPress plugin empire.<\/figcaption><\/figure>\n<p>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.<\/p>\n<figure id=\"attachment_217129\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217129 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/03-response.png\" alt=\"ChatGPT prompt to generate code for a WordPress plugin that duplicates content.\" width=\"915\" height=\"632\" \/><figcaption class=\"wp-caption-text\">This is what a license to print money looks like!<\/figcaption><\/figure>\n<p>ChatGPT generated the following code for the plugin in the blink of an eye:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\r\n&lt;?php\r\n\/*\r\nPlugin Name: Content Duplicator\r\nDescription: Allows users to duplicate posts, pages, or custom post types with one click.\r\nVersion: 1.0.0\r\nAuthor: Your Name\r\nAuthor URI: https:\/\/yourwebsite.com\r\n*\/\r\n\r\n\/\/ Add duplicate action links to post row actions\r\nfunction content_duplicator_add_duplicate_link( $actions, $post ) {\r\n    if ( current_user_can( &#039;edit_posts&#039; ) ) {\r\n        $actions&#x5B;&#039;duplicate&#039;] = &#039;&lt;a href=&quot;&#039; . wp_nonce_url( admin_url( &#039;admin-post.php?action=content_duplicator_duplicate_post&amp;post_id=&#039; . $post-&gt;ID ), &#039;content_duplicator_duplicate_post&#039; ) . &#039;&quot; title=&quot;Duplicate this item&quot; rel=&quot;permalink&quot;&gt;Duplicate&lt;\/a&gt;&#039;;\r\n    }\r\n    return $actions;\r\n}\r\nadd_filter( &#039;post_row_actions&#039;, &#039;content_duplicator_add_duplicate_link&#039;, 10, 2 );\r\n\r\n\/\/ Duplicate the post\r\nfunction content_duplicator_duplicate_post() {\r\n    if ( isset( $_GET&#x5B;&#039;post_id&#039;] ) ) {\r\n        $post_id = absint( $_GET&#x5B;&#039;post_id&#039;] );\r\n\r\n        if ( current_user_can( &#039;edit_posts&#039; ) &amp;&amp; wp_verify_nonce( $_GET&#x5B;&#039;_wpnonce&#039;], &#039;content_duplicator_duplicate_post&#039; ) ) {\r\n            $post = get_post( $post_id );\r\n\r\n            $args = array(\r\n                &#039;post_title&#039; =&gt; $post-&gt;post_title . &#039; (Duplicate)&#039;,\r\n                &#039;post_content&#039; =&gt; $post-&gt;post_content,\r\n                &#039;post_type&#039; =&gt; $post-&gt;post_type,\r\n                &#039;post_status&#039; =&gt; $post-&gt;post_status,\r\n                &#039;post_parent&#039; =&gt; $post-&gt;post_parent,\r\n                &#039;post_author&#039; =&gt; get_current_user_id(),\r\n            );\r\n\r\n            $new_post_id = wp_insert_post( $args );\r\n\r\n            if ( $new_post_id ) {\r\n                \/\/ Duplicate meta fields\r\n                $meta_fields = get_post_custom( $post_id );\r\n                foreach ( $meta_fields as $key =&gt; $values ) {\r\n                    foreach ( $values as $value ) {\r\n                        add_post_meta( $new_post_id, $key, $value );\r\n                    }\r\n                }\r\n\r\n                \/\/ Redirect to the duplicated post\r\n                wp_redirect( admin_url( &#039;post.php?action=edit&amp;post=&#039; . $new_post_id ) );\r\n                exit;\r\n            }\r\n        }\r\n    }\r\n}\r\nadd_action( &#039;admin_post_content_duplicator_duplicate_post&#039;, &#039;content_duplicator_duplicate_post&#039; );\r\n\r\n<\/pre>\n<p>It even provided a set of instructions after generating the code.<\/p>\n<figure id=\"attachment_217130\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217130 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/04-instructions.png\" alt=\"ChatGPT instructions.\" width=\"873\" height=\"786\" \/><figcaption class=\"wp-caption-text\">The code not only comes with instructions, but ChatGPT even says &#8220;Please&#8221;!<\/figcaption><\/figure>\n<p>I then uploaded the new plugin file to the <code>wp-content &gt; plugins<\/code> directory of my test site using The Hub&#8217;s <a href=\"https:\/\/wpmudev.com\/blog\/web-file-management-hosting\/\" target=\"_blank\" rel=\"noopener\">file manager<\/a>.<\/p>\n<figure id=\"attachment_217157\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217157 size-ratio-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/05-file-manager-1050x825.png\" alt=\"The Hub - File Manager\" width=\"1050\" height=\"825\" \/><figcaption class=\"wp-caption-text\">There&#8217;s a lot of action to unpack in this screenshot.<\/figcaption><\/figure>\n<p>And created a dummy post to test the plugin with&#8230;<\/p>\n<figure id=\"attachment_217160\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217160 size-ratio-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/08-original-post-1050x778.png\" alt=\"WordPress test post.\" width=\"1050\" height=\"778\" \/><figcaption class=\"wp-caption-text\">Did the plugin duplicate this cheesy post? Let&#8217;s find out!<\/figcaption><\/figure>\n<p>Here are the post&#8217;s menu options before activating the plugin&#8230;<\/p>\n<figure id=\"attachment_217161\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217161 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/09-post-before-plugin.png\" alt=\"WordPress Posts table with single post entry.\" width=\"764\" height=\"412\" \/><figcaption class=\"wp-caption-text\">A default post with default options.<\/figcaption><\/figure>\n<p>After activating the plugin&#8230;<\/p>\n<figure id=\"attachment_217158\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217158 size-ratio-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/06-activate-plugin-1050x598.png\" alt=\"WordPress Plugins screen - Activate Content Duplicator\" width=\"1050\" height=\"598\" \/><figcaption class=\"wp-caption-text\">&#8220;Activate Content Duplicator&#8221; &#8211; Sounds like a line from a Star Trek movie.<\/figcaption><\/figure>\n<p>Success!<\/p>\n<figure id=\"attachment_217159\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217159 size-ratio-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/07-plugin-activated-1050x516.png\" alt=\"WordPress Plugins screen - Plugin activated message.\" width=\"1050\" height=\"516\" \/><figcaption class=\"wp-caption-text\">A gratuitous screenshot proving that the plugin successfully activated.<\/figcaption><\/figure>\n<p>The plugin activated. But did it actually work?<\/p>\n<p>Here&#8217;s my test post again (note that the plugin added a new &#8220;Duplicate&#8221; item to the menu after activation).\u00a0I then clicked on &#8220;Duplicate&#8221; to see what happens&#8230;<\/p>\n<figure id=\"attachment_217162\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217162 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/10-post-after-plugin.png\" alt=\"WordPress Posts Table - Post entry with a new Duplicate item.\" width=\"769\" height=\"398\" \/><figcaption class=\"wp-caption-text\">ChatGPT even added a &#8220;Duplicate&#8221; menu item tooltip to the code!<\/figcaption><\/figure>\n<p>And a duplicate post was created!<\/p>\n<figure id=\"attachment_217163\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217163 size-ratio-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/11-duplicated-post-1050x674.png\" alt=\"An example of a duplicated WordPress post.\" width=\"1050\" height=\"674\" \/><figcaption class=\"wp-caption-text\">A duplicate of the original post.<\/figcaption><\/figure>\n<p>Here&#8217;s the table of posts showing entries for the original and duplicated post.<\/p>\n<figure id=\"attachment_217164\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-217164 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2023\/05\/12-post-table.png\" alt=\"WordPress Posts table with original post and duplicated post.\" width=\"795\" height=\"466\" \/><figcaption class=\"wp-caption-text\">The original post and its cloned version.<\/figcaption><\/figure>\n<p>I&#8217;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 &#8216;draft&#8217; instead of publishing it, but ChatGPT delivered a simple WordPress plugin that worked. It was basic, but it did the job.<\/p>\n<p>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.<\/p>\n<h2 id=\"expert-feedback\">Feedback from Our Expert Plugin Developers<\/h2>\n<p>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:<\/p>\n<ul>\n<li>&#8220;ChatGPT et al are decent at answering questions you already know the answer to.&#8221;<\/li>\n<li>&#8220;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\u2019d take ages for it to actually debug it line by line.&#8221;<\/li>\n<li>&#8220;Basically, it does what it says. However, it does what it says very literally. As in, it <i data-stringify-type=\"italic\">will<\/i> duplicate a post and its corresponding postmeta (custom) fields. However, it doesn&#8217;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).&#8221;<\/li>\n<li>If I was to be super-nitpicky about this, I&#8217;d also mention that it&#8217;s not L10n-ready &#8211; there won&#8217;t be an option to translate this plugin. But, that&#8217;s just being very nitpicky &#8211; I don&#8217;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 &#8220;very specific problem domain&#8221; 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.&#8221;<\/li>\n<\/ul>\n<p>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&#8217;s current capabilities to generate code:<\/p>\n<p><strong>1 &#8211; It&#8217;s important to exercise caution and not blindly accept ChatGPT-generated code as correct.<\/strong><\/p>\n<ul>\n<li>ChatGPT can provide answers, but it&#8217;s up to the user to assess whether the answer is correct or not.<\/li>\n<li>There is a risk of receiving incorrect or nonsensical answers from ChatGPT, both obvious and subtle.<\/li>\n<li>It&#8217;s important to exercise caution and not blindly accept the generated code as correct.<\/li>\n<li>ChatGPT&#8217;s output should be treated as autocomplete, making life easier but requiring caution and verification.<\/li>\n<\/ul>\n<p>The ability to discern good code from bad or nonsensical code, however, implies that&#8230;<\/p>\n<p><strong>2 &#8211; Users should have sufficient knowledge and understanding of WordPress plugin development to evaluate and modify the generated code as needed.<\/strong><\/p>\n<ul>\n<li>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.<\/li>\n<li>Using ChatGPT without sufficient knowledge can lead to negative consequences or unreliable code.<\/li>\n<li>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).<\/li>\n<\/ul>\n<p><strong>3 &#8211; Utilizing other resources, such as WordPress documentation, tutorials, and community forums, alongside ChatGPT can provide a more comprehensive understanding of WordPress plugin development.<\/strong><\/p>\n<ul class=\"p-rich_text_list p-rich_text_list__ordered\" data-stringify-type=\"ordered-list\" data-indent=\"0\" data-border=\"0\">\n<li>As you explore the possibilities of using ChatGPT for WordPress plugin development, it&#8217;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.<\/li>\n<li>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.<\/li>\n<li>It&#8217;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.<\/li>\n<\/ul>\n<h2 id=\"final-say\">Can ChatGPT Turn You Into a WordPress Plugin Developer?<\/h2>\n<p>In this article, we&#8217;ve explored how you can utilize ChatGPT to build simple custom WordPress plugins, even if you have limited coding experience.<\/p>\n<p>In other articles, we&#8217;ve seen that AI-powered tools like ChatGP can streamline your workflow, boost productivity, and unlock new possibilities (check out our recent article on\u00a0<a href=\"https:\/\/wpmudev.com\/blog\/wordpress-development-chatgpt\/\" target=\"_blank\" rel=\"noopener\">ways that ChatGPT can help you as a WordPress\u00a0developer<\/a>).<\/p>\n<p>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&#8217;s specific requirements.<\/p>\n<p>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.<\/p>\n<p>By utilizing the language model&#8217;s capabilities, you can generate code snippets, optimize functionality, and create user-friendly interfaces. However, it&#8217;s crucial to understand the generated code, review and refine it, and thoroughly test your custom plugins before deploying them to your live website.<\/p>\n<p>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.<\/p>\n<p><em>The bottom line:<\/em><\/p>\n<p>Here are my findings after trying to get ChatGPT to code me a plugin from scratch:<\/p>\n<ol>\n<li>I couldn\u2019t have gotten this done without the help of our experienced developers.<\/li>\n<li>Using ChatGPT to generate code without coding knowledge is really challenging &#8211; it helps to know what you are doing :)<\/li>\n<li>While ChatGPT is a powerful and valuable tool, it doesn&#8217;t seem like AI will replace skilled coders any time soon.<\/li>\n<\/ol>\n<h3>Interested in Developing WordPress plugins?<\/h3>\n<p>Check out some of our tutorials and articles on WordPress plugin development:<\/p>\n<ul>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/wordpress-plugin-development-guide\/\" target=\"_blank\" rel=\"noopener\">Getting Started with WordPress Plugin Development<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/wordpress-hooks\/\" target=\"_blank\" rel=\"noopener\">A Quick and In-Depth Guide to WordPress Hooks<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/object-oriented-plugins\/\" target=\"_blank\" rel=\"noopener\">Creating WordPress Plugins in An Object Oriented Way<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230; AI is the world&#8217;s most popular two-letter word right now. With all the recent news headlines about whether AI will take [&hellip;]<\/p>\n","protected":false},"author":774618,"featured_media":217131,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[],"tutorials_categories":[],"class_list":["post-217072","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/217072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/774618"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=217072"}],"version-history":[{"count":64,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/217072\/revisions"}],"predecessor-version":[{"id":217229,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/217072\/revisions\/217229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/217131"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=217072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=217072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=217072"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=217072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}