WordPress 7.0 just dropped, and with it comes the built-in WordPress AI Client. Honestly, it’s about time. For the last two years, I’ve seen developers hacking together messy CURL requests and managing half a dozen different SDKs just to get a simple prompt into OpenAI or Anthropic. It was a maintenance nightmare that made site migrations a headache.
The new API changes the game by providing a standardized abstraction layer. You no longer write code for “OpenAI” or “Gemini.” You write for the capability. If the site owner swaps their provider in the new Settings > Connectors screen, your plugin keeps working without you touching a single line of code. Furthermore, this architectural shift means we can finally build portable AI features that actually scale.
Understanding the WordPress AI Client Architecture
The core philosophy here is “Provider Agnostic.” Your plugin describes what it needs (an image, a summary, a translation), and WordPress handles the how. This is managed through the wp_ai_client_prompt() function, which returns a fluent builder object. Specifically, this builder allows you to chain requirements like aspect ratios, temperature, and model preferences.
I recently wrote about the WordPress 7.0 AI architecture, but today we’re getting our hands dirty by building a real-world image generation tool for the Media Library.
Building the Image Generation Logic
When building with the WordPress AI Client, I always wrap my logic in a helper function. This makes it easier to perform support checks before we ever hit the API. Here is how I structured the prompt builder for our plugin:
<?php
use WordPress\AiClient\Files\Enums\FileTypeEnum;
use WordPress\AiClient\Files\Enums\MediaOrientationEnum;
/**
* Configures the AI Client for image generation.
*
* @param string $prompt The user's text description.
* @param string $orientation Optional orientation (square, landscape, portrait).
* @return WP_AI_Client_Prompt_Builder
*/
function bbioon_get_image_prompt( string $prompt, string $orientation = '' ) {
$builder = wp_ai_client_prompt()
->with_text( $prompt )
->as_output_file_type( FileTypeEnum::inline() );
if ( ! empty( $orientation ) ) {
$builder->as_output_media_orientation( MediaOrientationEnum::from( $orientation ) );
}
return $builder;
}
Note that I’m using FileTypeEnum::inline(). This is a pragmatic choice because it returns base64-encoded data, allowing us to show an immediate preview in the admin UI before the user decides to save it to the database. Consequently, we avoid cluttering the Media Library with “hallucinated” garbage the user didn’t actually want.
Gating Features with Support Checks
One of the biggest “gotchas” with the WordPress AI Client is assuming it’s always ready. Just because the code is in Core doesn’t mean the user has configured a connector. If you enqueue your scripts without checking support, you’ll end up with a broken “Generate” button and a frustrated client.
Therefore, we use the is_supported_for_image_generation() method. This is a deterministic check—it doesn’t cost an API credit and it doesn’t make a network request. It simply checks if any active connector supports the requested capability.
<?php
function bbioon_enqueue_ai_assets( $hook_suffix ) {
if ( 'upload.php' !== $hook_suffix ) {
return;
}
// Don't load if the current provider can't actually do this.
$prompt_check = bbioon_get_image_prompt( 'test' );
if ( ! $prompt_check->is_supported_for_image_generation() ) {
return;
}
wp_enqueue_script( 'bbioon-ai-generator' );
}
add_action( 'admin_enqueue_scripts', 'bbioon_enqueue_ai_assets' );
Exposing the AI Client via REST API
To make this interactive, we need a custom REST endpoint. The GenerativeAiResult object returned by the client is serializable, meaning we can pass it directly to rest_ensure_response(). This keeps our controller methods incredibly lean.
<?php
function bbioon_rest_generate_image( WP_REST_Request $request ) {
$prompt = $request->get_param( 'prompt' );
$orientation = $request->get_param( 'orientation' );
$builder = bbioon_get_image_prompt( $prompt, $orientation );
$result = $builder->generate_image_result();
if ( is_wp_error( $result ) ) {
return $result; // WordPress handles the 400/500 status automatically.
}
return rest_ensure_response( $result );
}
For more technical details on how these endpoints integrate with the centralized Connectors UI, check out the official Make Core documentation.
The Future of WordPress Development
Building with the WordPress AI Client isn’t just about calling an LLM; it’s about following the “WordPress Way.” By using the built-in abstraction, we ensure our plugins are stable, performant, and future-proof. If you’ve been hesitant to dive into AI because of the fragmented API landscape, 7.0 is your signal to start shipping.
Look, if this WordPress AI Client stuff is eating up your dev hours, let me handle it. I’ve been wrestling with WordPress since the 4.x days.
Final Takeaway
Standardizing your AI implementation today prevents technical debt tomorrow. Stop hardcoding API keys and start using the Connectors API. You can explore the full source code for this implementation on the official WP AI Client GitHub. Now, go refactor that legacy OpenAI wrapper and ship something modern.