Skip to content

Add the Featured Image Generation UI#146

Open
dkotter wants to merge 53 commits intoWordPress:developfrom
dkotter:feature/image-generation-ui
Open

Add the Featured Image Generation UI#146
dkotter wants to merge 53 commits intoWordPress:developfrom
dkotter:feature/image-generation-ui

Conversation

@dkotter
Copy link
Collaborator

@dkotter dkotter commented Dec 16, 2025

What?

Partially closes #13. This only handles generating featured images, I'm assuming we'll want image generation in other places as well (though could be tracked in new Issues if we want).

Adds in the UI to trigger Featured Image Generation

Why?

This builds on top of the work done in #134, which added Abilities that could be used to generate an image and/or import an image. This PR adds in the actual UI that triggers those Abilities in the Featured Image section of the edit post screen as well as a new Ability to generate an image generation prompt.

How?

  • Modifies the Image Import Ability to allow passing in additional meta data that will be stored with the image. This allows us to easily track which images are AI generated based on a specific meta key
  • Adds a new Ability that is used to generate an image generation prompt. We pass this the content of the post along with the title and content type. Can pass in other context if desired along with optional style instructions
  • Loads in the necessary admin scripts and admin script data
  • Adds in all the needed javascript to wire things up, including:
    • a Generate featured image button that shows above the standard Set featured image button
    • When that button is clicked, first make a request to the get-post-details Ability. Then pass those details to the new image-prompt-generation Ability, along with our content and context. Take the prompt this generates and pass it to our existing image-generation Ability. Finally take the base64-encoded image it returns and pass it to our existing image-import Ability to import the image into the Media Library
  • Set this image as the Featured Image and change the text of the generation button from Generate featured image to Generate new featured image
  • Add a label below the Featured Image (if set and if AI generated) that makes it clear the image was AI generated

Testing Instructions

  1. Ensure you have valid AI credentials in place for OpenAI or Google under Settings > AI Credentials
  2. Ensure you turn on the Image Generation Experiment under Settings > AI Experiments
  3. Edit a piece of content that doesn't have a Featured Image yet
  4. Ensure you see the Generate featured image button
  5. Click this button (noting this will make an API request and will cost money)
  6. Ensure a proper loading state is shown and that eventually (this can take around 90s) an image is rendered in the normal featured image section
  7. Ensure this image imported properly into the Media Library and has a proper title and description
  8. Ensure the AI label shows below the image in the featured image section

To directly test the new generate image prompt Ability, can make an API requests like the following:

curl --location 'https://example.com/wp-json/wp-abilities/v1/abilities/ai/image-prompt-generation/run' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ****' \
--data '{
    "input": {
        "content": "This is the content of an article",
        "context": "Title: Hello World"
        "style": "Moody, dark colors"
    }
}'

Screenshots or screencast

New Generate featured image button showing above the default Set featured image button in the block editor sidebar Loading state of the new Generate featured image button AI featured image rendering properly with AI label beneath the image AI generated image shown in the media library

Test using WordPress Playground

The changes in this pull request can be previewed and tested using this WordPress Playground instance:

Click here to test this pull request.

Open WordPress Playground Preview

… closely to render the image and set/remove buttons
… an AI label below the image and only show that if the featured image has the AI meta set
…text using the post ID. Then take that context and generate an image prompt. Finally pass that prompt into our image generation function. Also modify our system instructions a bit
@dkotter dkotter added this to the 0.2.0 milestone Dec 16, 2025
@dkotter dkotter self-assigned this Dec 16, 2025
@github-actions
Copy link

github-actions bot commented Dec 16, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @prabinjha, @kurtrank.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: prabinjha, kurtrank.

Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: JasonTheAdams <jason_the_adams@git.wordpress.org>
Co-authored-by: karmatosed <karmatosed@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 59.45946% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.71%. Comparing base (6e60327) to head (5c41311).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
includes/Abilities/Image/Generate_Image_Prompt.php 53.57% 52 Missing ⚠️
.../Experiments/Image_Generation/Image_Generation.php 51.35% 18 Missing ⚠️
includes/Abilities/Image/Generate_Image.php 0.00% 3 Missing ⚠️
...bilities/Image/image-prompt-system-instruction.php 0.00% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #146      +/-   ##
=============================================
+ Coverage      50.45%   58.71%   +8.26%     
- Complexity       379      410      +31     
=============================================
  Files             27       29       +2     
  Lines           1992     2175     +183     
=============================================
+ Hits            1005     1277     +272     
+ Misses           987      898      -89     
Flag Coverage Δ
unit 58.71% <59.45%> (+8.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dkotter
Copy link
Collaborator Author

dkotter commented Jan 8, 2026

So it does make sense to have a model and system prompt focused on taking content and deriving an image prompt. It will need to understand that the content is a source of inspiration and to look for things like archetypes and what not within the content. This is some prompt engineering in and of itself. We may even take more parameters for things like describing the style of the image and such, which the content itself won't provide. This gets into the territory of a content guidelines as James has explored.

At this point I'm thinking it would be useful to have an "Image prompt from content" ability that takes in:

  1. Content to use as inspiration
  2. Style instructions (could be broken up into granular parameters)

This way we can really focus the system prompt on understanding its singular purpose, which I think will improve the resulting image prompt. We may consider having default style instructions so the generated images are somewhat consistent.

@JasonTheAdams Okay, I've updated this PR to take all the above into consideration. There is now a more specific Ability, image-prompt-generation, that allows you to pass in content, optional context (like title, author, content type) and optional style suggestions.

This Ability will then generate an image generation prompt which we then pass directly to an image generation model.

In my testing this is all working as expected but definitely open to suggestions on the system instructions we're using here and any other default instructions we may want in place to guide things.

@jeffpaul jeffpaul modified the milestones: 0.2.0, 0.3.0 Jan 13, 2026
@dkotter dkotter requested a review from jeffpaul February 4, 2026 21:19
@dkotter
Copy link
Collaborator Author

dkotter commented Feb 4, 2026

@jeffpaul This is ready for final review, noting I've not had success getting this to fully work in the Playground as the request to generate an image typically takes about 60 seconds and Playground always times out before that

@jeffpaul
Copy link
Member

jeffpaul commented Feb 5, 2026

This tested really nicely, and yes a bit of a lag in generating but there's :alot: happening in the background. To that specific extent, not something to hold up this PR, but perhaps helpful for a future iteration (but feel free to tell me I'm dumb here and we can skip it) would be some simple "loading text" that describes what's happening (e.g. "Generating image generation prompt from post content...", "Generating image from generated prompt...") so folks understand why its not an immediate response?

One thing that I think is worth pausing on to decide how best to land this experiment is the specific alternative text, title, caption, description for generated images. Currently the Title is set as AI Generated Image and the Description is This is an AI generated image.

Screenshot 2026-02-05 at 12 23 33 PM

Perhaps an iteration here to the Alt Text getting generated as well from the resulting image (perhaps hooking into the alt text ability?), the Title getting a truncated or condensed version of the generated alt text, the Caption stays empty as that's meta that more often is also rendered on the front end and may be best left for author/editor input, and the Description gets some provenance info (though anyone who knows me knows I'd LOVE to see something like c2pa-js used to store meta here) so something like “Generated by ExampleAI Image Model v2 on 05 Feb 2026. Prompt: ‘Minimal illustration of a 1700s sailor staring out to see from a dock.’”?

@dkotter
Copy link
Collaborator Author

dkotter commented Feb 5, 2026

This tested really nicely, and yes a bit of a lag in generating but there's :alot: happening in the background. To that specific extent, not something to hold up this PR, but perhaps helpful for a future iteration (but feel free to tell me I'm dumb here and we can skip it) would be some simple "loading text" that describes what's happening (e.g. "Generating image generation prompt from post content...", "Generating image from generated prompt...") so folks understand why its not an immediate response?

The only issue here is while yes, we are running lots of things one after the other, they all run fairly quickly besides the actual image generation. So we could add a progress message but I think what we'd see is the message shows then is replaced before someone can actually read it, which may be more annoying then helpful. But the actual image generation part will take time (OpenAI is usually around 60 seconds, Google is typically faster but still ~40 seconds) so maybe still useful to have those messages?

One thing that I think is worth pausing on to decide how best to land this experiment is the specific alternative text, title, caption, description for generated images

I'm open to any suggestions here, I purposely left it fairly basic as a starting point.

Perhaps an iteration here to the Alt Text getting generated as well from the resulting image (perhaps hooking into the alt text ability?), the Title getting a truncated or condensed version of the generated alt text

My one concern in regards to alt text is that's a separate Experiment and we can't assume users will have both of those active (Image Generation and Alt Text Generation). In that situation, not sure how we handle that, as the Alt Text Generation Ability won't be available to use if it's not turned on. I guess we could have a light-weight duplicate of that specific to Image Generation, though I could see some complaints there from users wondering why AI is generating alt text when they don't have that Experiment turned on.

the Caption stays empty as that's meta that more often is also rendered on the front end and may be best left for author/editor input

Yeah, I agree on keeping this empty

the Description gets some provenance info (though anyone who knows me knows I'd LOVE to see something like c2pa-js used to store meta here) so something like “Generated by ExampleAI Image Model v2 on 05 Feb 2026. Prompt: ‘Minimal illustration of a 1700s sailor staring out to see from a dock.’”?

Main issue here is the Ability that generates an image only returns the generated image, it doesn't return anything else, like provider, model, prompt used, etc. We could look to update the Ability to do that if we think that would be valuable, though I'd also need to figure out if the AI Client can tell us what provider and model was used (I'm assuming so but not something I've tried).

@jeffpaul
Copy link
Member

jeffpaul commented Feb 5, 2026

The only issue here is while yes, we are running lots of things one after the other, they all run fairly quickly besides the actual image generation. So we could add a progress message but I think what we'd see is the message shows then is replaced before someone can actually read it, which may be more annoying then helpful. But the actual image generation part will take time (OpenAI is usually around 60 seconds, Google is typically faster but still ~40 seconds) so maybe still useful to have those messages?

Ok, yeah maybe we ignore this for now and see if there's community feedback about the time to completion and if some sort of loading info is helpful.

My one concern in regards to alt text is that's a separate Experiment and we can't assume users will have both of those active (Image Generation and Alt Text Generation). In that situation, not sure how we handle that, as the Alt Text Generation Ability won't be available to use if it's not turned on. I guess we could have a light-weight duplicate of that specific to Image Generation, though I could see some complaints there from users wondering why AI is generating alt text when they don't have that Experiment turned on.

Perhaps if the alt text experiment is disabled / that ability is not available, we fall back to adding in directly the raw image gen prompt (knowing that'll likely include sub-optmial "Generate image of" sort of context, but at least someone generating the image could immediately edit/remove it?).

Main issue here is the Ability that generates an image only returns the generated image, it doesn't return anything else, like provider, model, prompt used, etc. We could look to update the Ability to do that if we think that would be valuable, though I'd also need to figure out if the AI Client can tell us what provider and model was used (I'm assuming so but not something I've tried).

Let's chat about how quickly feasible this could be, balancing that with still getting this feature shipped since its otherwise near ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image Generation

3 participants