WordPress 7.0 Now Has Built-In AI — What Developers Need to Know

|
8 mins reading time

WordPress 7.0 introduces one of the most exciting features in years — the AI Client is now part of Core directly, not just another third-party Plugin.

Before this, adding AI features to a Plugin meant doing everything yourself — connecting to each provider's API, managing API keys for clients, handling errors differently every time. Every Plugin did it their own way with no shared standard.

WordPress 7.0 changes all of that by introducing a central PHP API that lets a Plugin simply declare what it needs, then WordPress handles routing the request to whichever AI Model is available — whether the site is running Claude, GPT, or Gemini.

Getting Started From Scratch

First, you need to connect an AI to your website. WordPress 7.0 provides a built-in UI that lets you choose a provider based on the API key you have—whether that's Anthropic, Google, or OpenAI. Simply navigate to Settings > Connectors, enter your API key, and you're ready to go!

The most important thing to do before calling AI is checking whether that site has a Provider configured, because not every site will have one set up.

$builder = wp_ai_client_prompt( 'test' );

if ( ! $builder->is_supported_for_text_generation() ) {
    // No provider configured — show a notice or hide the UI
    return;
}

// Reaching this line means we're good to go

Generating Text

Everything starts with a single function — wp_ai_client_prompt(), which is a Fluent Builder similar to the Query Builder pattern familiar from Laravel. Methods can be chained one after another.

$text = wp_ai_client_prompt( 'Write a Meta Description for an article about WordPress Caching' )
    ->using_system_instruction( 'You are an SEO Expert specializing in WordPress.' )
    ->using_temperature( 0.7 )  // 0 = precise, 1 = creative
    ->using_max_tokens( 200 )
    ->generate_text();

if ( is_wp_error( $text ) ) {
    error_log( $text->get_error_message() );
    return;
}

echo wp_kses_post( $text );

Getting JSON Back With a Schema

Instead of having AI return plain text that you then have to parse yourself, you can define a JSON Schema upfront to specify exactly what shape you want the data in. This is perfect for anything that needs to be rendered on a page or stored in a database.

// กำหนดหน้าตาของข้อมูลที่ต้องการ
$schema = array(
    'type'  => 'array',
    'items' => array(
        'type'       => 'object',
        'properties' => array(
            'title'       => array( 'type' => 'string' ),
            'description' => array( 'type' => 'string' ),
            'category'    => array( 'type' => 'string' ),
            'difficulty'  => array(
                'type' => 'string',
                'enum' => array( 'beginner', 'intermediate', 'advanced' ),
            ),
        ),
        'required' => array( 'title', 'description', 'category', 'difficulty' ),
    ),
);

$json = wp_ai_client_prompt( 'แนะนำ 5 หัวข้อบทความสำหรับเว็บ WordPress Developer ภาษาไทย' )
    ->as_json_response( $schema )
    ->generate_text();

if ( is_wp_error( $json ) ) {
    return;
}

// ได้ Array พร้อมใช้เลย ไม่ต้อง Parse เอง
$topics = json_decode( $json, true );

foreach ( $topics as $topic ) {
    echo '<h3>' . esc_html( $topic['title'] ) . '</h3>';
    echo '<p>' . esc_html( $topic['description'] ) . '</p>';
    echo '<small>หมวด: ' . esc_html( $topic['category'] ) . ' | ระดับ: ' . esc_html( $topic['difficulty'] ) . '</small>';
}

Generating Images

Before generating images, it's worth checking whether the configured Provider actually supports image generation, since not every Provider can do it.

$builder = wp_ai_client_prompt( 'test' );

if ( ! $builder->is_supported_for_image_generation() ) {
    echo 'Provider ที่ตั้งค่าไว้ไม่รองรับการสร้างรูปภาพ';
    return;
}

Once confirmed, generating an image is straightforward:

use WordPress\AiClient\Files\Enums\FileTypeEnum;
use WordPress\AiClient\Files\Enums\MediaOrientationEnum;

$image_file = wp_ai_client_prompt( 'ภาพ Hero Banner สำหรับเว็บ Tech Blog สไตล์ Minimal สีน้ำเงินเข้ม' )
    ->as_output_file_type( FileTypeEnum::inline() )
    ->as_output_media_orientation( MediaOrientationEnum::from( 'landscape' ) )
    ->generate_image();

if ( is_wp_error( $image_file ) ) {
    return;
}

echo '<img src="' . esc_url( $image_file->getDataUri() ) . '" alt="Hero Banner">';

If you want to give clients multiple variations to choose from, you can request several at once:

$images = wp_ai_client_prompt( 'โลโก้สำหรับร้านกาแฟสไตล์ Minimalist พื้นหลังขาว' )
    ->as_output_media_orientation( MediaOrientationEnum::from( 'square' ) )
    ->generate_images( 4 );  // ขอมา 4 แบบพร้อมกัน

if ( is_wp_error( $images ) ) {
    return;
}

echo '<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem;">';
foreach ( $images as $index => $image ) {
    echo '<div>';
    echo '<img src="' . esc_url( $image->getDataUri() ) . '" style="width: 100%;">';
    echo '<button onclick="selectImage(' . $index . ')">เลือกแบบนี้</button>';
    echo '</div>';
}
echo '</div>';

Choosing a Model With Fallback

If a Plugin needs a specific Model, you can define a fallback order and WordPress will pick the first one available on that site. If none of them are available, it automatically falls back to the most suitable Model it can find.

$result = wp_ai_client_prompt( 'วิเคราะห์ Tone ของบทความนี้และแนะนำวิธีปรับปรุง' )
    ->using_model_preference(
        'claude-sonnet-4-6',       // อยากได้ตัวนี้มากที่สุด
        'gemini-3.1-pro-preview',  // ถ้าไม่มีก็ตัวนี้
        'gpt-5.4'                  // หรืออันนี้ก็ได้
    )
    ->generate_text_result();

if ( is_wp_error( $result ) ) {
    return;
}

// ดูได้ว่า Model และ Provider ไหนตอบกลับมาจริงๆ
$model    = $result->getModelMetadata();
$provider = $result->getProviderMetadata();
$tokens   = $result->getTokenUsage();  // ดู Token ที่ใช้ไป

error_log( 'ใช้ Model: ' . $model->getName() . ' จาก ' . $provider->getName() );
error_log( 'Token ที่ใช้: ' . $tokens->getTotal() );

Using generate_text_result() instead of generate_text() gives you this extra metadata, which is extremely useful for debugging or tracking AI usage costs across a site.

Connecting to the REST API

For anything that needs to be called from JavaScript on the front-end, the recommended approach is to create a dedicated REST Endpoint and manage permissions on the PHP side. Letting JS call AI directly is not advisable because access control becomes much harder to enforce.

add_action( 'rest_api_init', function () {
    register_rest_route( 'myplugin/v1', '/generate-description', array(
        'methods'             => 'POST',
        'callback'            => 'myplugin_generate_description',
        'permission_callback' => function () {
            return current_user_can( 'edit_posts' );
        },
    ) );
} );

function myplugin_generate_description( WP_REST_Request $request ) {
    $product_name = sanitize_text_field( $request->get_param( 'product_name' ) );

    $result = wp_ai_client_prompt(
        sprintf( 'Write a product description for "%s" in approximately 100 words.', $product_name )
    )
        ->using_system_instruction( 'You are a Copywriter specializing in E-commerce.' )
        ->using_temperature( 0.8 )
        ->generate_text_result();

    return rest_ensure_response( $result );
}

Then on the JavaScript side, it's just a simple fetch:

const response = await fetch( '/wp-json/myplugin/v1/generate-description', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'X-WP-Nonce': wpApiSettings.nonce,
    },
    body: JSON.stringify({ product_name: 'Handmade Genuine Leather Bag' }),
} );

const data = await response.json();
console.log( data );

This isn't just a new feature being added to WordPress — it fundamentally changes how developers work with AI inside the platform. Everyone now speaks the same language, uses the same API, and site owners manage everything from one place. No more juggling API keys across a dozen different Plugins.

Source: WordPress Core Dev Notes — Introducing the AI Client in WordPress 7.0 Introducing the AI Client in WordPress 7.0

Designil PDPA Banner Thai Woo AIO Banner

author - aum watcharapon
Aum Watcharapon
👨🏻‍💻 WordPress Expertiser

Subscribe to newsletter

doaction will send notifications when new articles are available on the website, and you can unsubscribe at any time.

More Articles

What’s New in WordPress 7.0? Summary of Features for Users and Developers

WordPress 7.0 Major Update: Release Date and Key Features WordPress Version 7.0 is set to be a massive update, with the official full version scheduled for release on April 9, 2026. This coincides with WordCamp Asia 2026 in Mumbai, India. We have summarized the 6 core features of this update as follows: 1. Native AI System WordPress is introducing a new AI infrastructure designed to make life easier for developers through the WP AI Client. This serves as a central API that allows for seamless connections to various AI providers—such as OpenAI, Claude, or Gemini—without the need for developers to write custom integration code from scratch. 2. Integrated API Management External API keys will now be managed collectively within the new Connectors Settings page. This section is designed to handle not only AI integrations but also other future third-party services. Additionally, there is a system for [...]

Read more

If you have any questions or need advice about WordPress, feel free to ask.

Office

  • © do action co., ltd. 2024
    66 Soi Petchkasem 98/1, Petchkasem Road,
    Bangkhae Nuea, Bangkhae,
    Bangkok, Thailand
    10160