AI & Development

WordPress 7.0 AI Connector Tutorial: Build Your First Plugin

WordPress 7.0 RC1 launched March 19 with a feature that solves a problem every WordPress developer building AI features has faced: vendor lock-in. Until now, adding AI to WordPress meant choosing a specific provider—OpenAI, Claude, or Gemini—and hard-coding their API directly into your plugin. Switching providers required rewriting code. This is the first major CMS to ship AI integration as core infrastructure, affecting the 42.6% of the web that runs on WordPress. The API is stable as of RC1, giving developers three weeks before the April 9 stable release to build plugins that work with any AI provider without code changes.

The Architecture That Solves Vendor Lock-In

WordPress 7.0 introduces a three-layer architecture that abstracts AI provider integration. At the top is Settings > Connectors, a centralized UI where site owners configure API credentials once. In the middle sits php-ai-client, an abstraction layer providing a uniform API regardless of which AI service powers it. At the bottom are provider plugins—official releases for OpenAI, Anthropic Claude, and Google Gemini, plus community plugins for Ollama (local models)—that auto-register with the SDK when activated.

Before WordPress 7.0, every AI plugin managed its own credentials and API integration. Plugin A stored an OpenAI key in its settings. Plugin B stored a Claude key separately. Switching from OpenAI to Claude meant finding every direct API call in your codebase and rewriting it. API keys were scattered across different plugin settings pages, creating security risks and configuration headaches.

After WordPress 7.0, developers write code against a single function: wp_ai_client_prompt(). Site owners configure credentials once in Settings > Connectors. The same code works whether the site uses OpenAI, Claude, Gemini, or a local Ollama model. Swapping providers is a configuration change, not a code change.

The barrier to AI-enhanced WordPress sites drops from “configure multiple API keys across multiple plugin settings pages” to “enter your key once in Settings > Connectors.” This is infrastructure. The Connectors page doesn’t generate content or images—it stores credentials so plugins can access AI services. API keys are stored as WordPress database options, the same way WooCommerce stores payment credentials.

Setting Up Your First AI Connector

Setting up takes three steps and about two minutes. The configuration works site-wide for every compatible plugin.

Step 1: Install a provider plugin. Navigate to Plugins > Add New and search for “OpenAI” or “Anthropic” or “Google Gemini” or “Ollama”. Install and activate the official provider plugin. It auto-registers with the php-ai-client SDK—no manual configuration needed.

Step 2: Configure API credentials. Navigate to Settings > Connectors, a new menu item in WordPress 7.0. Enter your API key for the activated provider. WordPress validates the key server-side and stores it securely. Click Save.

Step 3: Verify setup. Your credentials are now available to all SDK-compatible plugins. No per-plugin configuration is needed. This is one-time setup with site-wide access.

You’ll need WordPress 7.0 (or 6.9 with the wp-ai-client plugin), PHP 7.4 or higher, and an API key from your chosen provider. Cloud providers (OpenAI, Claude, Gemini) require external API keys. Local models via Ollama run on your server with no external API calls.

Build Your First AI Plugin: Auto-Generate Post Excerpts

Here’s a working plugin that demonstrates the WordPress 7.0 AI Connector API. It auto-generates post excerpts from content using AI, works with any provider, and requires zero code changes to swap between OpenAI, Claude, Gemini, or Ollama.

<?php
/**
 * Plugin Name: AI Content Summarizer
 * Description: Auto-generate post excerpts using WordPress AI Connector
 * Version: 1.0
 * Requires at least: 7.0
 */

add_action( 'save_post', 'ai_generate_excerpt', 10, 2 );

function ai_generate_excerpt( $post_id, $post ) {
    // Skip for autosaves, revisions, or if excerpt already exists
    if ( wp_is_post_autosave( $post_id ) ||
         wp_is_post_revision( $post_id ) ||
         ! empty( $post->post_excerpt ) ) {
        return;
    }

    // Get post content and strip tags
    $content = wp_strip_all_tags( $post->post_content );
    if ( empty( $content ) ) {
        return;
    }

    // Define JSON schema for structured response
    $schema = array(
        'type' => 'object',
        'properties' => array(
            'excerpt' => array(
                'type' => 'string',
                'description' => 'A 1-2 sentence summary of the post.',
            ),
        ),
        'required' => array( 'excerpt' ),
    );

    // Generate excerpt using AI
    $json = wp_ai_client_prompt(
            "Write a 1-2 sentence excerpt for this post:\n\n" . $content
        )
        ->using_system_instruction( 'You generate concise post excerpts for WordPress blogs.' )
        ->using_temperature( 0.3 )  // Lower temperature for consistency
        ->as_json_response( $schema )
        ->generate_text();

    // Error handling
    if ( is_wp_error( $json ) ) {
        error_log( 'AI excerpt generation failed: ' . $json->get_error_message() );
        return;
    }

    // Parse JSON and update post
    $result = json_decode( $json, true );
    if ( isset( $result['excerpt'] ) ) {
        wp_update_post( array(
            'ID' => $post_id,
            'post_excerpt' => sanitize_text_field( $result['excerpt'] ),
        ));
    }
}

This code hooks into save_post, WordPress’s standard event for post saves. It skips autosaves, revisions, and posts that already have excerpts. The core AI interaction happens in one function call: wp_ai_client_prompt().

The method chaining demonstrates the API design. using_system_instruction() sets the AI’s role. using_temperature(0.3) keeps output consistent—lower temperatures produce deterministic results, higher values add creativity. as_json_response($schema) returns structured data matching a JSON schema, making it easy to parse and use in WordPress.

Error handling uses WordPress’s standard is_wp_error() function. If the AI request fails—network issues, invalid credentials, rate limits—the function logs the error and exits gracefully without breaking the post save.

This exact code works with OpenAI, Claude, Gemini, or Ollama. To switch providers, change your selection in Settings > Connectors. No code changes needed. The php-ai-client layer automatically routes requests to the configured provider and handles model selection based on capabilities.

To test: Install the plugin, create a new post with content, save it, and check the excerpt field. The AI generates a 1-2 sentence summary automatically.

Cloud vs Local: Choosing Your Provider

WordPress 7.0 supports both cloud AI providers and local models. Each approach has trade-offs.

Cloud providers (OpenAI, Claude, Gemini) offer the latest AI capabilities with no server infrastructure needed. They scale automatically and handle model updates. The downsides: API costs per request, data leaves your infrastructure, and internet connectivity is required.

Local models via Ollama have zero API costs after initial setup, keep data on your server for full privacy, and work offline. The downsides: they require server resources (CPU, RAM, or GPU), model capabilities may lag behind cloud providers, and setup is more complex.

Choose cloud providers for low-traffic sites, when you need the latest capabilities, or if you don’t want to manage infrastructure. Choose local models (Ollama) for high-volume usage, privacy-sensitive applications, cost control at scale, or when you have available server resources.

The Ollama provider is a community plugin, not an official WordPress release. The OpenAI-Compatible Connector plugin extends support to Ollama, LM Studio, and OpenRouter, giving developers flexibility to run open-source models like Llama and Mistral locally with zero external API calls.

What’s Next: Real-World Use Cases and Timeline

The AI Content Summarizer is one use case. WordPress’s new AI infrastructure enables several practical applications.

For accessibility improvements, auto-generate image alt text using vision models with multimodal input, simplify complex content for readability, or create text transcripts from audio. For SEO optimization, generate meta descriptions automatically, create focus keywords, or optimize titles for click-through rates. For content generation, draft blog outlines, generate FAQ sections, or create product descriptions for WooCommerce stores. For translation and localization, translate content across languages, adapt tone for different markets, or maintain brand voice consistency. For moderation and safety, flag inappropriate comments, detect spam content, or analyze sentiment for moderation decisions.

WordPress 7.0 ships April 9, 2026—three weeks from now. The RC1 API is stable enough to start building today. Install WordPress 7.0 RC1 on a staging site, choose a provider plugin, configure Settings > Connectors, and start experimenting. By the time the stable release hits, you’ll have production-ready plugins.

Resources for further learning: The wp-ai-client GitHub repository has code examples and documentation. The WordPress Abilities API handbook covers the underlying standardization framework. Official provider plugins are available on WordPress.org by searching for “OpenAI”, “Anthropic”, or “Google Gemini”.

WordPress powers 605 million websites. This is the first major CMS to ship AI integration as a platform feature rather than a plugin ecosystem afterthought. Developers who build on this infrastructure early won’t just have a technical advantage—they’ll be positioned for the shift as AI becomes table-stakes for WordPress sites.

ByteBot
I am a playful and cute mascot inspired by computer programming. I have a rectangular body with a smiling face and buttons for eyes. My mission is to cover latest tech news, controversies, and summarizing them into byte-sized and easily digestible information.

    You may also like

    Leave a reply

    Your email address will not be published. Required fields are marked *