Skip to content

feat: Add standalone AI image generation interface to the Media Library.#258

Merged
jeffpaul merged 8 commits intoWordPress:developfrom
zeus2611:feature/Integrate-Image-Generation-into-Media-Library
Mar 5, 2026
Merged

feat: Add standalone AI image generation interface to the Media Library.#258
jeffpaul merged 8 commits intoWordPress:developfrom
zeus2611:feature/Integrate-Image-Generation-into-Media-Library

Conversation

@zeus2611
Copy link
Contributor

@zeus2611 zeus2611 commented Feb 26, 2026

What?

Closes #254

Adds a standalone image generation interface accessible from the WordPress Media Library, allowing users to generate AI-powered images outside the block editor.

Why?

#235 introduced image generation within the block editor. This PR extends that functionality into the Media Library so users can generate images independently of the post editor context, as outlined in #254. This opens up the image generation capability to any workflow that involves the Media Library.

How?

Backend (PHP)

  • Image_Generation.php: Added register_admin_menu() to register a "Generate Image" submenu item under Media using add_media_page()
  • Image_Generation.php: Added render_admin_page() to output the admin page shell with a React mount point (#ai-image-generation-root)
  • Image_Generation.php: Added inject_generate_image_button() hooked to admin_footer-upload.php to inject a "Generate Image" action button into the Media Library header alongside "Add New Media File". Uses a capture-phase click listener to bypass WordPress's media grid JS event delegation
  • Image_Generation.php: Updated enqueue_assets() to load scripts on upload.php and media_page_ai-image-generation in addition to post editor screens

Frontend (React/TypeScript)

  • GenerateImageStandalone.tsx: New standalone React component providing the full image generation flow:
    • Idle → prompt input
    • Generating → spinner with progress messages
    • Preview → generated image with Save / Refine / Regenerate / Cancel actions
    • Success → confirmation with option to generate another
  • media-library.tsx: Mounts GenerateImageStandalone on the admin page's #ai-image-generation-root element
  • index.ts: Added import './media-library' entry point

Temporary Scaffolding

  • uploadImageLocal() in GenerateImageStandalone.tsx is a local fallback for image upload functionality. Once Inline image generation #235 is merged, this will be replaced with the shared uploadImage function from ../functions/upload-image during rebase.

Use of AI Tools

Implementation was planned and executed with assistance from Gemini (Antigravity). All code was reviewed, tested, and validated manually in a local WordPress environment.

Testing Instructions

  1. Add valid AI credentials in Settings > AI Credentials (Google or OpenAI support image generation)
  2. Ensure the image generation experiment is turned on under Settings > AI Experiments
  3. Navigate to Media > Library in wp-admin
  4. Verify a "Generate Image" button appears in the header next to "Add New Media File"
  5. Click the "Generate Image" button
  6. Verify you are navigated to the Media > Generate Image admin page (not the upload panel)
  7. Enter an image generation prompt and click Generate
  8. Verify a loading spinner appears with progress text
  9. Once the image is generated, verify the preview is rendered with buttons: Save to Media Library, Regenerate, and Cancel
  10. Click Save to Media Library and verify the image is imported successfully with a confirmation message
  11. Click Generate Another Image and verify you return to the prompt input
  12. Try Cancel to return to the idle state
  13. Navigate to Media > Generate Image in the sidebar and verify the same standalone UI loads correctly
  14. If the alt text experiment is enabled, verify alt text is generated during image import

Testing Instructions for Keyboard

  1. Tab to the "Generate Image" button in the Media Library header and press Enter
  2. On the Generate Image page, Tab to the textarea, type a prompt, then Tab to the Generate button and press Enter
  3. After generation, Tab through the action buttons (Save, Regenerate, Cancel) and verify each is focusable and activatable with Enter
  4. Verify focus management returns to an appropriate element after state transitions

Screenshots or screencast

Before After
Screenshot 2026-02-26 at 4 55 39 PM Screenshot 2026-02-26 at 4 56 09 PM
1 2 3 4 5 6 Open WordPress Playground Preview

@github-actions
Copy link

github-actions bot commented Feb 26, 2026

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.

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

Co-authored-by: zeus2611 <n1schay@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@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 Feb 26, 2026

Codecov Report

❌ Patch coverage is 61.29032% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.68%. Comparing base (3b059d9) to head (693f6b8).
⚠️ Report is 20 commits behind head on develop.

Files with missing lines Patch % Lines
.../Experiments/Image_Generation/Image_Generation.php 61.29% 12 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #258      +/-   ##
=============================================
+ Coverage      57.48%   57.68%   +0.20%     
- Complexity       563      567       +4     
=============================================
  Files             35       35              
  Lines           2907     2933      +26     
=============================================
+ Hits            1671     1692      +21     
- Misses          1236     1241       +5     
Flag Coverage Δ
unit 57.68% <61.29%> (+0.20%) ⬆️

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.

@jeffpaul jeffpaul requested review from dkotter and jeffpaul February 26, 2026 14:29
@jeffpaul jeffpaul added this to the 0.4.0 milestone Feb 26, 2026
@zeus2611
Copy link
Contributor Author

zeus2611 commented Feb 26, 2026

Investigated the failing PHP trunk tests — the fatal error originates in wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php (a WP core file) rather than this PR's changes. It's a PSR namespace mismatch between the interface contract and implementation, which explains why all PHP versions pass on WP latest but fail on WP trunk. Happy to retest once trunk stabilizes, or let me know if there's a preferred workaround.

@dkotter
Copy link
Collaborator

dkotter commented Feb 26, 2026

Investigated the failing PHP trunk tests — the fatal error originates in wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php (a WP core file) rather than this PR's changes. It's a PSR namespace mismatch between the interface contract and implementation, which explains why all PHP versions pass on WP latest but fail on WP trunk. Happy to retest once trunk stabilizes, or let me know if there's a preferred workaround.

Yes, known issue between the version of the AI Client we load and the version that is now merged into trunk (and will be in WP 7.0). Tracking the fixes for this on #242

Copy link
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we're waiting for #235 to get merged before this can be 100% finished but did an initial review here and left some comments

@jeffpaul
Copy link
Member

jeffpaul commented Mar 3, 2026

Besides some threaded comments above, my primary testing feedback is the post-generation flow. Here is what currently results:

Screenshot 2026-03-03 at 3 10 25 PM

Perhaps we instead send folks back to the Media Library with the generated image present (as they have the Generate Image button and second level menu item they can select to generate another image?

Screenshot 2026-03-03 at 3 09 30 PM Screenshot 2026-03-03 at 3 09 47 PM

Alternatively, perhaps we send them to the Attachment details modal?

Screenshot 2026-03-03 at 3 09 21 PM

Or to the Edit Media page?

Screenshot 2026-03-03 at 3 10 16 PM

I'm curious if @karmatosed has a particularly strong preference here?

@karmatosed
Copy link
Member

@jeffpaul thanks for looping me in. I think in this case the 'attachment page' works. I typically like things to stay on same screen but it will get lost if we keep it there and that screen doesn't really have a good highlight. I like idea of even adding a 'regenerate' option there but that's another scope creep.

@jeffpaul jeffpaul mentioned this pull request Mar 3, 2026
20 tasks
@zeus2611
Copy link
Contributor Author

zeus2611 commented Mar 4, 2026

@dkotter @jeffpaul & @karmatosed. I intentionally kept the user on the Generate Image page after saving to allow batch generation without back-and-forth navigation — which felt like the primary use case for someone in the Media Library context vs the block editor, where inserting the image is the end goal.

That said, I think the middle ground makes sense: I'll add a "View in Media Library" link alongside the "Generate Another Image" button in the success state. This gives users who want to inspect or edit the attachment a direct path without forcing navigation for those who want to keep generating.

@zeus2611 zeus2611 force-pushed the feature/Integrate-Image-Generation-into-Media-Library branch 2 times, most recently from 0e9d62e to 96e9bc0 Compare March 4, 2026 10:59
@zeus2611 zeus2611 force-pushed the feature/Integrate-Image-Generation-into-Media-Library branch from 96e9bc0 to eb2e195 Compare March 4, 2026 11:35
…ve image refinement functionality from the standalone component.
@zeus2611 zeus2611 force-pushed the feature/Integrate-Image-Generation-into-Media-Library branch from eb2e195 to 0fcbe7b Compare March 4, 2026 11:45
@zeus2611
Copy link
Contributor Author

zeus2611 commented Mar 4, 2026

@dkotter @jeffpaul @karmatosed — updated the success state to include two buttons: "Generate Another Image" (keeps the current flow intact for batch generation) and "View in Media Library" which takes the user directly to the attachment details page for the saved image.

The attachment details page felt like the right destination over the media grid since the user can immediately review and edit the auto-generated title, alt text and description — which is likely the next thing they'd want to do. WordPress's built-in prev/next navigation in the top-right also lets them browse previously generated images without any additional custom code on our end.

Screenshots attached showing the updated success state. Happy to adjust if you'd prefer the link goes to the media grid instead.

Screenshot 2026-03-04 at 3 41 58 PM Screenshot 2026-03-04 at 3 42 24 PM

@dkotter
Copy link
Collaborator

dkotter commented Mar 4, 2026

Tested and things look good to me. I've added new E2E tests to cover these changes. I think the last thing here is some additional refactoring that can now be done since #235 has been merged (see comment). Once done, this will be good to merge

@jeffpaul jeffpaul requested a review from dkotter March 5, 2026 14:39
Copy link
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested again and things work fine so approving this.

I do think there's some refinement we could make here around the loading state. I'm also seeing some weird shifting after an image is generated and then when you choose to import that or regenerate. Seems the width of the container is changing so the image decreases in size a bit. Not a blocker but something we can look to refine

@zeus2611
Copy link
Contributor Author

zeus2611 commented Mar 5, 2026

Thanks for testing and the approval, @dkotter!

Agreed on both the loading state and the container width shift — I can reproduce the latter too. Would you prefer I address these here before merge, or should we track them as a follow-up issue so this PR can land cleanly? Happy to do either.

@dkotter
Copy link
Collaborator

dkotter commented Mar 5, 2026

Agreed on both the loading state and the container width shift — I can reproduce the latter too. Would you prefer I address these here before merge, or should we track them as a follow-up issue so this PR can land cleanly? Happy to do either.

@zeus2611 I'd say so we don't hold this PR up for merge (and getting a release out) we can tackle these in a follow-up PR. I think the layout shift will be easy but may want more conversation around the loading state, trying to figure out what works best both here and when generating images within the editor

@zeus2611
Copy link
Contributor Author

zeus2611 commented Mar 5, 2026

Sounds good, @dkotter! That aligns with my thinking too — while working on the last change request I did consider touching the loading state but held back since getting it right across both the inline and standalone contexts felt like something worth discussing as a team rather than deciding unilaterally. I'll open a follow-up issue to track both the layout shift and the loading state so we have a clear place for that conversation.

@jeffpaul jeffpaul merged commit 3926290 into WordPress:develop Mar 5, 2026
21 of 27 checks passed
@jeffpaul
Copy link
Member

jeffpaul commented Mar 5, 2026

@zeus2611 FYI I created #270 to track the follow-up work

@zeus2611 zeus2611 deleted the feature/Integrate-Image-Generation-into-Media-Library branch March 5, 2026 19:42
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.

Integrate Image Generation into Media Library

4 participants