-
Notifications
You must be signed in to change notification settings - Fork 43
Add Alt Text Generation experiment #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Add Alt Text Generation experiment #156
Conversation
Adds AI-powered alt text generation for images using vision models: - Block editor integration via InspectorControls for Image blocks - Media Library integration for upload.php and media modals - Supports attachment IDs, URLs, and data URIs as input - Uses AI vision models (Claude, GPT, Gemini) to analyze images - Generates concise, descriptive alt text (max 125 chars) Includes shared run-ability.ts utility for Abilities API fallback.
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @andreizanik, @hellobertha. 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. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #156 +/- ##
=============================================
- Coverage 50.33% 49.45% -0.89%
- Complexity 366 463 +97
=============================================
Files 26 29 +3
Lines 1951 2283 +332
=============================================
+ Hits 982 1129 +147
- Misses 969 1154 +185
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds AI-powered alt text generation capabilities for images across WordPress's block editor and media library interfaces using vision-capable AI models.
Key Changes:
- Integrates alt text generation into the Image block via InspectorControls with generate/regenerate functionality
- Adds media library support for upload.php, media modals, and attachment edit screens through DOM manipulation
- Implements a shared
runAbilityutility that gracefully falls back from Abilities API to REST calls
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| webpack.config.js | Adds two webpack entry points for the block editor and media library scripts |
| src/utils/run-ability.ts | Implements shared utility for executing abilities with fallback to REST API |
| src/experiments/alt-text-generation/types.ts | Defines TypeScript interfaces for Image block attributes |
| src/experiments/alt-text-generation/media.ts | Implements DOM-based alt text generation for media library and modals |
| src/experiments/alt-text-generation/index.tsx | Registers block editor filter to inject controls into Image blocks |
| src/experiments/alt-text-generation/components/AltTextControls.tsx | React component providing UI for alt text generation in block inspector |
| includes/Experiments/Alt_Text_Generation/Alt_Text_Generation.php | Experiment registration with asset enqueuing hooks for editor and media contexts |
| includes/Experiment_Loader.php | Registers the new experiment in the experiments array |
| includes/Abilities/Alt_Text_Generation/system-instruction.php | System prompt defining alt text generation requirements (concise, descriptive, accessible) |
| includes/Abilities/Alt_Text_Generation/Alt_Text_Generation.php | Core ability implementation handling image processing, data URI conversion, and AI prompting |
| docs/experiments/alt-text-generation.md | Comprehensive documentation of hooks, data flow, testing steps, and implementation notes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return null; | ||
| } | ||
|
|
||
| $contents = file_get_contents( $file_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'file_get_contents' to read potentially large image files could cause memory issues. Consider checking file size first or using streaming approaches for larger files to prevent memory exhaustion.
| protected function download_remote_image_to_temp_file( string $url ) { | ||
| if ( ! function_exists( 'download_url' ) ) { | ||
| require_once ABSPATH . 'wp-admin/includes/file.php'; | ||
| } | ||
|
|
||
| $temp_file = download_url( $url ); | ||
|
|
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The download_remote_image_to_temp_file method passes the untrusted image_url directly into download_url, which will make an outbound HTTP request from the server to any host the caller supplies. A user with the upload_files capability can invoke the ai/alt-text-generation REST ability and use this to perform server-side requests to arbitrary (including internal) URLs, which is an SSRF risk even though the response body is only used as an image file. To reduce this risk, restrict outbound requests to a well-defined set of trusted hosts or validate the URL against private/local address ranges before calling download_url.
|
@Jameswlepage for the overlap between this experiment and the image generation one, perhaps we default the image gen prompt as the alt text there but still present the button to generate alternate alt text ;) for those images? |
|
@Jameswlepage does this actually close #44 or is there still more to add to fully cover the functionality from that issue? |
|
@Jameswlepage can you add tests here like was done in https://github.com/WordPress/ai/pull/147/changes#diff-0cf348eda48cae411ad9d44a2e5b449603a971f2313b0a849893ff4cf8280c46? |
|
…g patterns in other files
…e existing WordPress hooks to add that button in. Adjust our JS accordingly with this new setup.
…tton and ensure this works properly
…ply better protections around path traversal
Addresses #44
Summary
Adds AI-powered alt text generation for images using vision models:
Implementation Details
ai/alt-text-generationability with vision models (Claude Haiku, GPT-5 Nano, Gemini Flash)editor.BlockEditfilterrun-ability.tsutility for Abilities API with REST fallbackTest plan