Using AI tools to spin up a WordPress plugin

With AI so prominent in our world today, we thought it’d be interesting to explore how developers can use these tools to create or improve WordPress plugins. This post also takes you through a step-by-step process of building a WordPress Plugin using the popular AI coding assistant — Cursor.

While AI can be a reliable assistant, it’s not a full replacement for human expertise. A skilled developer still needs to review the output, catch bugs, optimize performance, and ensure the code is secure and scalable.

That said, we’re clearly in the era of natural language programming. You probably won’t be spinning up an entire CMS with a single prompt — and don’t expect to get a full-featured page builder either — but AI can help speed up many parts of the process. Even low-code enthusiasts can benefit from it, while advanced developers are finding smarter, faster ways to build.

AI coding tools overview

No matter the tool used, online or desktop, most AI code generators have the following in common:

  • They have ingested massive volumes of data and have been trained on code repositories.
  • They offer autocomplete and intelligent code suggestions that save time.
  • They are proficient in many programming languages.
  • They’re context-aware, meaning they can understand the structure of your codebase.
  • They interpret natural language prompts, even with minor typos.
  • Some let you switch between different large language models (LLMs).
  • Most support plugin systems or extensions.
  • Many include tools for debugging and refactoring.

So, who are the key players in the AI coding space today?

  1. ChatGPT: The most recognizable name in AI right now. ChatGPT doesn’t require any setup and can generate code, explain what it’s doing, and respond to follow-up questions — all in one place.
  2. GitHub Copilot: Built by GitHub and OpenAI, Copilot integrates directly into your favorite IDEs and suggests code in real-time as you type. It’s like pair programming with an AI dev.
  3. Grok: Similar to ChatGPT and Claude, Grok is xAI’s tool available to X users and is known for its attitude.
  4. Gemini: This is Google’s family of all-purpose AI-powered tools, which is similar to ChatGPT.
  5. Windsurf: This is an IDE specializing in anticipating a developer’s needs.

A few words about using Cursor AI

To build our plugin, we chose to use Cursor AI, a rising favorite among developers. Cursor AI is a fork of the VSCode IDE, which is why it looks and feels familiar. Being flexible, your VSCode settings and preferences can be imported to Cursor AI.

As a full-featured open source IDE, there are many extensions available and numerous ways to access code documentation.

Cursor’s Chat has multiple modes, each optimized for a different kind of task.

Cursor chat mode
Cursor chat mode.

You can switch between them using the mode picker (Cmd+.) or via keyboard shortcuts:

  • Ask Mode: Best for quick questions, explanations, or planning features. For example, you might type “What programming language is used in this codebase?” and get a contextual answer based on your open files. Access it with Cmd+L (Mac) or Ctrl+L (Windows/Linux).
  • Agent Mode: Ideal when you want Cursor to reason across your whole codebase and make broader changes, like generating files, implementing a new feature, or refactoring. You can say something like “Create a documentation file based on what’s in /plugins/contentwriter.” Trigger this mode using Cmd+I or Ctrl+I.
  • Manual Mode: Use this when you want more control and only need the AI to work within a specific file or snippet. For instance, you might ask it to “Refactor theme.json using components found in ../docs.” This mode is activated automatically when you start editing directly, or through the Command Palette.

Plugin spin-up workflow

If you’ve only been using ChatGPT to write your code, you may be missing out on what AI code assistance can do. True, general AI tools can spin up a valid WordPress plugin, but it certainly may not be the most efficient way to test or debug code.

That’s where tools like Cursor AI come in — they combine AI with a full-featured IDE to guide you through a more structured, developer-centric workflow.

A good way to start working with AI coding assistants is by prompting them with something you’re already familiar with. Pick a small, well-scoped project. Don’t jump into complex features or large-scale plugin development right away. And definitely don’t expect the AI to build your entire plugin off a single vague prompt. Just like you would with any development task, begin by writing down your objectives in plain language.

For this walkthrough, we’ll create a plugin called Custom Writer that registers a new user role in WordPress. This role can create and edit posts, but it shouldn’t be able to delete anything or access other post types.

Step 1: Open the plugin directory

Launch Cursor and use File > Open Folder to navigate to your <code>/wp-content/plugins<code> directory. This sets the stage for your plugin build.

Step 2: Start a new chat session

Press Cmd + Shift + L (or Ctrl + Shift + L on Windows) to begin a new chat.

Switch to Ask Mode by pressing Cmd + L / Ctrl + L so we can start with a planning prompt. In this mode, Cursor will help you reason through your idea without jumping straight to code.

Above the main prompt input, you’ll see a field labeled Add Context. This is where you can describe your objective in full. Be specific, even if your spelling isn’t perfect — Cursor is forgiving.

Here’s what we type in:

Take note of the @WordPress keyword — this tells Cursor to reference the official WordPress documentation. It’s one of the simplest ways to ensure your plugin follows best practices.

Using Cursor Ask mode
Using Cursor Ask mode.

Step 3: Review the markdown instructions

Once you press Send, Cursor replies with a detailed markdown document. It outlines everything your plugin should do — from setting up hooks to cleaning up on uninstall.

Here’s a snapshot of what Cursor includes:

  • Plugin header details (name, version, license)
  • Code structure (a single .php file in a custom plugin folder)
  • Role creation with add_role()
  • Specific capabilities (edit_posts, publish_posts, etc.)
  • Hooks for activation, deactivation, and uninstall
  • Security, performance, and testing recommendations

You can tweak the instructions before proceeding, but we’re happy with them as-is.

Step 4: Switch to Agent mode and build the plugin

Now it’s time to actually generate the code.

Switch to Agent Mode by pressing Cmd + Shift + I (or Ctrl + Shift + I). This gives Cursor permission to work across your codebase and execute multi-step tasks.

Press Enter, and you see the Run Command button appear.

Cursor run command
Cursor run command.

Click the Run Command, and just like that, Cursor will create your plugin. You should see a new folder (e.g., custom-writer-role) with a single .php file inside.

Folder and code files generated by Cursor
Folder and code files generated by Cursor.

Step 5: Review and accept the file

Open the file Cursor generated. You can make edits here, like updating the plugin author or refining the inline comments.

Once you’re satisfied, click Accept File. Don’t worry, you can always edit it later. This just confirms the file should be part of your codebase.

Step 6: Activate the plugin in WordPress

Head over to your WordPress Admin dashboard. Under Plugins, locate your new plugin and activate it.

Activate WordPress plugin created by Cursor
Activate WordPress plugin created by Cursor.

If everything was generated correctly, you’ll see a success message and the plugin will be live.

Step 7: Test the new role

Create a new user and assign them the Custom Writer role. Your testing should indicate:

  • New user role successfully created
  • Only posts can be created.
  • Posts can be edited and viewed but not deleted.

Step 8: Discover and fix UI quirks

One thing you will notice is that the Quick Edit link is still available in the post list. While it doesn’t allow deletion, we didn’t ask for it, and it can be confusing for users.

Debugging the plugin
Debugging the plugin.

Head back to Cursor and start a new prompt asking for help removing Quick Edit.

While creating the demo for this guide, we did a series of prompts asking Cursor to take different approaches to remove Quick Edit. At one point, we saw references to “user_switch,” making us wonder if there was a conflict with the Switch User Role plugin. (This was the only plugin we were running besides our plugin.)

Cursor told us there would be a conflict after we alerted it to this potential issue. Another round of prompts ensued. During this time, we discovered that the new user was unable to log in because a higher permission level was needed.

Another round of prompts began with no success. At certain intervals, Cursor would remove Quick Edit, but the Edit function would also be removed. Feeling lost, we asked Cursor to summarize where we were to make sure we were comfortable with what it understood. At one point, we found ourselves asking, “What do you think?”

Finally, Cursor found a way to resolve all the issues and gave us a summary of the changes made.

Step 9: Observe additional behaviors

While testing, we also noticed:

  • The Media Library is inaccessible, even though we didn’t mention it. This is a reminder: if you don’t explicitly request a capability, the AI likely won’t include it.
  • Cursor’s summary mentioned that it “works for posts and pages,” but the plugin correctly blocks access to pages. So, the AI slightly overexplained, but the behavior is correct.

Step 10: Keep testing and iterating

From here, you can install additional plugins, test compatibility, and refine your role as needed. When something breaks or doesn’t behave as expected, return to Cursor with follow-up prompts.

You’ll find yourself doing this often — asking follow-up questions, rephrasing instructions, or even just asking “What do you think?” to get Cursor’s perspective.

That’s where Cursor really shines: the feedback loop is fast, and the assistant improves with every iteration.

Don’t throw caution to the wind

Just because you can ask an AI to generate a plugin doesn’t mean you should — at least, not without thinking it through first.

Before prompting, take time to define what your plugin is supposed to do. Consider its purpose, required features, and any potential dependencies. Ask yourself: could this plugin conflict with major extensions like WooCommerce? If the answer is maybe, include that in your prompt.

The more context you give the AI, the better your results. Be specific. Describe your goals clearly. Don’t hold back.

AI may feel magical, but building responsibly still matters. Keep in mind the same pillars you consider when coding by hand:

  • Security – sanitize inputs, check capabilities, follow best practices
  • Performance – avoid redundant queries, keep logic tight
  • Accessibility – consider user roles, UI elements, and inclusive interaction
  • Testing – try edge cases, mix plugins, and validate functionality
  • Deployment – prepare for versioning, rollbacks, and scalability
  • Refactoring – revisit your code, not just once, but regularly

Summary

The landscape of assisted-generated code changes every minute. This is reminiscent of the early days of search, when there were numerous entries. In the end, just a few of them survived. This is what may ultimately happen here as well, although open source may take us in a different direction.

We suggest you explore a number of AI tools using the same initial prompt, then compare coding journeys and results. Be open to the possibility that you may need to change your preferred application as the landscape continues to evolve.

As AI tools evolve, your workflow should too — and that starts with the right environment.

Kinsta’s developer-friendly WordPress Hosting gives you the speed, control, and tools you need to build, test, and launch with confidence. Whether you’re working locally with DevKinsta or deploying to staging, we’ve got your back.

Explore Kinsta’s WordPress hosting plans and start building smarter.

The post Using AI tools to spin up a WordPress plugin appeared first on Kinsta®.

版权声明:
作者:zhangchen
链接:https://www.techfm.club/p/213107.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>