Building any WP Plugin With AI Agents

Written by Software Engineer

January 2, 2026
Building any WP Plugin With AI Agents

AI tools like ChatGPT, Claude, and Gemini are now capable of acting as real coding partners.

Today, you can build full WordPress plugins without being a PHP expert. With the right prompts, these AI agents can generate entire plugin structures, write classes, create admin pages, handle AJAX or REST API logic, and even help you debug errors.

In this guide, you’ll learn exactly how to work with AI in planning your plugin, prompting the AI for each stage, refining the code, and finally exporting and testing it inside WordPress.

Setting Up Your Workspace


Before you start generating code with an AI agent, you need an environment where you can create, edit, and test the plugin.

A local WordPress setup is the easiest way to do this. Tools like DevKinsta, LocalWP, XAMPP, or Docker enable you to run WordPress on your computer without affecting a live site. Once it’s installed, you’ll be working mainly inside the /wp-content/plugins/ folder where your new plugin will live.

For editing files, you can use any code editor you’re comfortable with, alongside popular AI tools like ChatGPT, Claude, etc. VS Code also works great with extensions like GitHub Copilot. You can also use AI-focused editors like Cursor, which allows you to write and refine your plugin code directly with AI inside your editor.

With this setup in place, you're ready to start building WordPress plugins with AI.

25%

💸 EXTRA 25% OFF ALL VERPEX MANAGED HOSTING PLANS FOR WORDPRESS

with the discount code

SERVERS-SALE

SAVE NOW

Step-by-Step: Building Your First Plugin with AI Agents


Building a WordPress plugin with an AI agent is not a one-prompt task. It’s a back-and-forth workflow where you guide the AI, give it context, ask for improvements, test the output, and let it refine the code.

To show you how this works in real life, I’ll walk through the same process I used recently to build an AI Reporter plugin entirely with AI tools.

AI Reporter plugin

The steps below are the same ones you’ll follow to build any plugin. The only thing that changes is the idea.

Step 1: Describe the Plugin You Want to Build

Start by telling the AI exactly what you want the plugin to do. Don’t worry about technical details, just describe the functionality in plain English.

Here’s the type of prompt used when starting AI Reporter:

I want to build a WordPress plugin called "AI Reporter."
It should take a title and one or more URLs, extract the content from the URLs, and generate a full article using an AI model.
It should have an admin page, settings for API keys, and an AJAX workflow for generating the article.
Create the initial plugin structure, following WordPress coding standards.
Use OOP structure and add basic security checks.

The AI generated a full plugin skeleton:

ai-reporter/
├── ai-reporter.php
├── includes/
│   ├── class-ai-reporter.php
│   ├── class-ai-reporter-loader.php
│   ├── class-ai-reporter-openai.php
│   ├── class-ai-reporter-gemini.php
├── admin/
│   ├── class-ai-reporter-admin.php
│   └── partials/ai-reporter-admin-display.php
└── assets/ai-reporter-admin.css

The next thing you do is replicate this in your code environment (wp-content/plugins/), and if you use an IDE like Cursor, you just let it create the files and folders for you. You can even ask AI to describe what each file will do and why it exists to be sure all files are important.

Step 2: Generate Admin Menu and Pages

The next step is to make sure this plugin can actually be used by a human, and in WordPress, that starts with adding it to the dashboard menu. If a plugin doesn’t show up in the admin sidebar, it basically doesn’t exist for most users.

So after you have your skeleton in place, your next move is to ask the AI to create an admin menu item and a basic page where everything will live.

With AI Reporter, the prompt looked something like this:

Now add an admin menu page for the "AI Reporter" plugin.
It should:
- Add a top-level menu item called "AI Reporter" in the WordPress dashboard.
- Use a class called AI_Reporter_Admin to handle admin functionality.
- Load a separate template file for the main plugin page.
Follow WordPress coding standards.

From that, the AI generated an AI_Reporter_Admin class (in admin/class-ai-reporter-admin.php) with a method that hooks into admin_menu and registers the menu:

public function add_plugin_admin_menu() {
    add_menu_page(
        'AI Reporter Settings',
        'AI Reporter',
        'read',
        $this->plugin_name,
        [$this, 'display_plugin_setup_page'],
        'dashicons-admin-generic',
        81
    );
}

You don’t need to memorise this; the whole point is that the AI writes it for you. What you should understand is what’s happening:

  • add_menu_page tells WordPress, “Show a new top-level item in the sidebar.”
  • "AI Reporter" is what the user sees in the menu.
  • $this->plugin_name becomes the slug for the page.
  • display_plugin_setup_page is the method that will actually output the HTML for the page.

The AI also wired this method into the loader in class-ai-reporter.php, so the hook is actually registered when the plugin runs:

private function define_admin_hooks() {
    $plugin_admin = new AI_Reporter_Admin($this->get_plugin_name(), $this->get_version());

    $this->loader->add_action('admin_menu', $plugin_admin, 'add_plugin_admin_menu');
}

Then you ask the AI to create the actual page template. For AI Reporter, that was a separate partial in admin/partials/ai-reporter-admin-display.php, and the admin class simply included it:

public function display_plugin_setup_page() {
    include_once 'partials/ai-reporter-admin-display.php';
}

Inside that partial, the AI generated a basic layout with a heading, tabs, and a form. At first, it can be as simple as:

<div class="wrap ai-reporter-admin-wrap">
    <h1>AI Reporter</h1>
    <p>Configure your settings and generate articles using AI.</p>
</div>

You can always come back later and ask the AI to refine the design, add tabs, or expand the form. The important thing at this stage is that:

  1. The plugin now has a visible entry in the WordPress admin menu.

  2. Clicking it loads a real page that you can expand on.

Practically, once the AI gives you this code, you paste the AI_Reporter_Admin class into admin/class-ai-reporter-admin.php, paste the template into admin/partials/ai-reporter-admin-display.php, and make sure the main plugin class (AI_Reporter) is loading the admin class and registering the hooks.

After saving everything, go back to your WordPress dashboard, refresh, and you should see the name of your plugin in the left sidebar.

Step 3: Add User Settings (Using the WordPress Settings API)

Once your plugin is visible in the WordPress admin and has its own page, the next logical step is giving users a place to configure things. Almost every plugin needs settings. In WordPress, the proper way to store and manage these settings is through the Settings API.

With AI, you don’t have to remember how to register settings or how sanitization works. You simply describe what you want, and the AI handles the boilerplate.

Here’s the kind of prompt used while building AI Reporter:

Add a settings section to the AI Reporter plugin.

The settings should include:
- Gemini API key (text input)
- OpenAI API key (text input)
- Additional instructions (textarea)
- A multi-select field where the user can select up to 3 existing posts to use as writing style examples

Use the WordPress Settings API and add sanitization for each field.
Update the admin page to show these settings inside a "Setup" tab.

From this prompt, the AI generated code in three pieces:

  1. Registering the settings

  2. Building the settings UI (the input fields)

  3. Saving and sanitizing the values

Here’s roughly what the AI produced in AI_Reporter_Admin:

public function options_update() {
    register_setting(
        'ai_reporter_options',
        'ai_reporter_options',
        [$this, 'validate']
    );

    add_settings_section(
        'ai_reporter_main_section',
        'Style Guide Settings',
        null,
        'ai_reporter_options'
    );

    add_settings_field(
        'gemini_api_key',
        'Gemini API Key',
        [$this, 'gemini_api_key_callback'],
        'ai_reporter_options',
        'ai_reporter_main_section'
    );

    add_settings_field(
        'openai_api_key',
        'OpenAI API Key',
        [$this, 'openai_api_key_callback'],
        'ai_reporter_options',
        'ai_reporter_main_section'
    );
}

Again, you don’t need to memorize this. What matters is understanding what’s happening:

  • register_setting tells WordPress: “I’m storing settings under this option name.”
  • add_settings_section groups related fields together.
  • add_settings_field creates each input field.

The AI also generates callback functions that output the actual HTML fields. For example, the API key field:

public function openai_api_key_callback() {
    $options = get_option('ai_reporter_options');
    $value = isset($options['openai_api_key']) ? $options['openai_api_key'] : '';
    echo '<input type="text" name="ai_reporter_options[openai_api_key]" value="' . esc_attr($value) . '" class="regular-text">';
}

These callback functions are inserted into the admin page template, so once you refresh the Settings tab, you immediately see the fields.

The last part is validation, which the AI also writes for you:

public function validate($input) {
    $valid = [];
    $valid['openai_api_key'] = sanitize_text_field($input['openai_api_key'] ?? '');
    $valid['gemini_api_key'] = sanitize_text_field($input['gemini_api_key'] ?? '');
    return $valid;
}

Here, sanitization is important because it prevents invalid input, unsafe characters, and potential security issues. Again, you’re not expected to know which functions to use — the AI selects them automatically.

Step 4: Add the Plugin Logic (AJAX, REST API, or Any Custom Functionality)

Once your settings are saving correctly, you’re ready to add the actual “brains” of your plugin. This is typically where most beginners get stuck when coding manually, because it involves routing requests, handling user input, making API calls, or performing some kind of processing. But with AI tools, this step becomes surprisingly approachable as long as you guide the AI one piece at a time.

In the case of AI Reporter, this logic involved taking user inputs (title and URLs), processing them, and generating an article via an AI model. To build that feature, the first prompt was something like:

Now add the main functionality.

Create an AJAX action called "generate_article".
It should:
- Verify a nonce
- Read the submitted title and URLs
- Fetch content from each URL
- Build a prompt
- Pass the data to an AI provider class
- Return the generated article as JSON

Update the admin page so the form triggers this AJAX call.

The important part here is the structure of what we asked the AI to do. You’re describing the workflow, and the AI writes the code for each step.

Here’s the kind of code the AI produced for the AJAX handler in AI Reporter:

public function generate_article() {
    check_ajax_referer('ai_reporter_nonce', 'nonce');

    $title = sanitize_text_field($_POST['title']);
    $source_urls = array_map('esc_url_raw', $_POST['source_urls']);

    $provider = new AI_Reporter_OpenAI($options['openai_api_key']);
    $result = $provider->generate_article($title, $source_urls);

    wp_send_json_success($result);
}

You’ll notice the pattern:

  • Verify the request
  • Sanitize the data
  • Process the logic
  • Respond with wp_send_json_success

This pattern works for any plugin feature, not just AI-powered ones. For example:

  • If you’re building an SEO plugin: process metadata
  • If you’re building a form plugin: submit and store entries
  • If you’re building a WooCommerce extension: calculate something and return a response
  • If you’re building a reporting tool: query posts and return JSON

The AI will write the logic for whatever you describe, and it usually gets the WordPress-specific functions right on the first try.

To connect this to your admin page, the AI also writes the JavaScript. In AI Reporter, it created a simple script that listens for the form submission and sends the AJAX request:

$('#generate-article-form').on('submit', function(e) {
    e.preventDefault();

    $.post(ajaxurl, {
        action: 'generate_article',
        nonce: $('input[name="nonce"]').val(),
        title: $('#ai-reporter-title-input').val(),
        source_urls: $('#ai-reporter-sources').val().split("\n")
    }, function(response) {
        $('#article-content').html(response.data);
    });
});

Again, this is about understanding how to communicate with the AI. If the AI misunderstands something (maybe it uses the wrong hook name, or puts a file in the wrong place), you simply correct it:

"The AJAX handler should be inside the admin class, not in the main plugin file.
 Rewrite just that part."

Or:

"This JavaScript should go into assets/admin.js and be enqueued properly.
 Fix and update the code."

And the AI adjusts everything instantly.

For AI Reporter, the logic became more advanced, but all of that was generated the same way: one clear instruction at a time.

The key takeaway is this: You don’t build plugin logic in one giant prompt. You build it as a series of small, clear tasks, and the AI handles each one.

Step 5: Debug Using AI Agents

Once your plugin starts to have real functionality, such as forms that submit, AJAX calls that fire, and API requests that run, this is where you’ll inevitably run into errors. And that’s normal. Every plugin, even professionally built ones, goes through multiple rounds of trial and error.

But here’s where building with AI becomes dramatically easier than traditional development, as the AI can debug your plugin for you.

For example, when AI Reporter was being built, there was a moment where activating the plugin caused a fatal error:

Fatal error: Uncaught Error: Call to undefined method AI_Reporter_Admin::generate_article()

Instead of opening 10 tabs to StackOverflow or trying to hunt down where the missing method should be, the debugging process looked like this:

Here is the exact error when I activate the plugin:

[FATAL ERROR MESSAGE HERE]

Fix the issue. Show me the corrected code and explain why the error happened.

Another example: At one point, AI Reporter had a malformed AJAX request:

Uncaught ReferenceError: ajaxurl is not defined

I pasted the entire console error into ChatGPT and asked:

Fix this JavaScript error. I'm using WordPress admin AJAX, so ajaxurl should be available.

The AI instantly identified that the JavaScript file wasn’t enqueued in the admin context and suggested the correct enqueue method:

wp_enqueue_script(
    'ai-reporter-admin-js',
    plugins_url('../assets/admin.js', __FILE__),
    ['jquery'],
    $this->version,
    true
);

And then added:

wp_localize_script('ai-reporter-admin-js', 'aiReporterData', [
    'ajaxurl' => admin_url('admin-ajax.php'),
]);

Step 6: Export and Test Your Plugin

Once everything is working, the final step is packaging your plugin and testing it like a real WordPress user would. This is where you confirm that your plugin behaves cleanly outside of your development environment, and it’s also the moment where everything comes together.

The first thing you do is export the plugin folder by compressing it into a .zip file. This creates a fully installable plugin file.

Next, go into your WordPress dashboard and upload it just like any other plugin:

  • Plugins > Add New > Upload Plugin
  • Select your zip file
  • Click Install Now, then Activate
90%

💸 90% OFF YOUR FIRST MONTH WITH ALL VERPEX SHARED WEB HOSTING PLANS

with the discount code

MOVEME

Save Now

Wrapping Up


By now, you’ve seen exactly how the process works. You don’t need to be a senior PHP engineer or remember every WordPress hook by heart. What you do need is a clear idea, the ability to describe it well, and the willingness to build your plugin step by step alongside an AI coding partner.

The workflow is always the same:

  • Describe what you want
  • Let the AI generate the next piece
  • Paste it into your plugin folder
  • Test it
  • Fix or refine anything using the AI
  • Export and activate it like any real plugin

If you want to see a real example of what’s possible, you can check out the complete AI Reporter plugin.

Frequently Asked Questions

Do AI plugins slow down website performance?

Some AI plugins may consume resources, which can affect website speed. To minimize impact, choose well-optimized plugins and regularly monitor your site’s performance.

Are AI plugins compatible with all WordPress themes?

Most AI plugins work seamlessly with popular WordPress themes, but it’s advisable to test them with your specific theme or consult the plugin documentation for compatibility information.

Do I even need plugins for my website?

To get the most out of WooCommerce and sell more effectively, you will need to use plugins. This is also essential for customization.

Is it possible to create my own plugins?

You can create your own plugins, but you should only do so if you have the relevant experience.

Discount

💰 90% OFF YOUR FIRST MONTH WITH ALL VERPEX HOSTING PLANS FOR WORDPRESS

with the discount code

MOVEME

Grab the Discount