Prompt: How to Build an Image Generation Plugin with the WordPress AI Client
← AI for Your Work
This tutorial guides developers through building a WordPress plugin that integrates the built-in AI Client API to generate images directly within the Media Library. It explains the provider-agnostic architecture, prompt configuration, REST API creation, and frontend integration required to implement AI image generation seamlessly in WordPress.
Copy This Prompt
I am building a WordPress plugin to generate images in the Media Library. Write the PHP function to configure the AI Client prompt for a text prompt: '[prompt_text]', with an optional aspect ratio of '[orientation]' (square, landscape, or portrait). Use `FileTypeEnum::inline()` to get the image as base64 data, and set a model preference order of 'gpt-5.4', 'gemini-3.1-pro-preview', then fallback to any available model. Include a support check to ensure image generation is available before executing.
Example input
Use the placeholders in the prompt with permitted, anonymized source data.
Expected output
Follow the output format requested in the prompt and verify the result against the source.
Tools
WordPress 7.0+, PHP 7.4+, Node.js 20+, Composer, AI Provider Account (OpenAI, Google, etc.)
