Summary
Implement WP-CLI command to generate alternative text for image attachments using the WordPress AI Client, following WordPress/ai#44.
What was added
New subcommand under wp ai generate:
wp ai generate alt-text <attachment_id>
Capabilities
- Validates attachment exists and is image type
- Converts image to data URI for vision model processing
- Generates alt text via WordPress AI Client
- Enforces 125-character limit (WCAG guideline)
- Updates
_wp_attachment_image_alt post meta
- Supports all standard options:
--provider, --model, --temperature, --top-p, --top-k, --max-tokens, --system-instruction
Example usage
$ wp ai generate alt-text 123
Success: Alt text generated and saved for attachment 123: A WordPress logo on a blue background
Implementation
- Added
generate_alt_text() private method to AI_Command class
- Uses WordPress AI Client
with_file() builder method for vision input
- Error handling: missing attachment, non-image type, unreadable file, unsupported model
- Test coverage: added Behat scenarios for error cases
Related
Summary
Implement WP-CLI command to generate alternative text for image attachments using the WordPress AI Client, following WordPress/ai#44.
What was added
New subcommand under
wp ai generate:Capabilities
_wp_attachment_image_altpost meta--provider,--model,--temperature,--top-p,--top-k,--max-tokens,--system-instructionExample usage
$ wp ai generate alt-text 123 Success: Alt text generated and saved for attachment 123: A WordPress logo on a blue backgroundImplementation
generate_alt_text()private method toAI_Commandclasswith_file()builder method for vision inputRelated
feat/alt-text-generation