Add WP-CLI command for bulk alt text generation#436
Add WP-CLI command for bulk alt text generation#436adamsilverstein wants to merge 6 commits intoWordPress:developfrom
Conversation
Introduce `wp ai alt-text generate` to backfill alt text for existing media library images using the ai/alt-text-generation ability. Supports --batch-size, --dry-run, --force, --ids, and --delay flags. Processes images server-side in batches with progress reporting and memory management. Closes WordPress#435
|
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 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 #436 +/- ##
=============================================
+ Coverage 67.72% 68.56% +0.83%
- Complexity 959 994 +35
=============================================
Files 60 61 +1
Lines 4836 5000 +164
=============================================
+ Hits 3275 3428 +153
- Misses 1561 1572 +11
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:
|
Add php-stubs/wp-cli-stubs for PHPStan to recognize WP-CLI classes. Add cli\progress\Bar ignore pattern since the WP-CLI progress bar internals are not in the stubs package. Fix type annotations and add unreachable returns after WP_CLI::error() for static analysis. Add 10 integration tests covering: admin user setup, attachment ID querying (with/without alt text, force flag, specific IDs, invalid IDs), memory cleanup, summary output, and dry-run display.
Add WP-CLI stubs that allow testing the CLI command without requiring a full WP-CLI install. This raises patch coverage above the codecov threshold and exercises the main process_images() and generate() paths. New tests cover: - process_images generates and saves alt text - process_images handles decorative images - process_images skips existing alt text without --force - process_images force flag overwrites existing alt text - process_images handles WP_Error responses from the ability - print_summary with zero results path - ensure_admin_user error when no admin exists - generate errors when ability is not registered
Cover the main entry point paths not previously tested:
- generate() with no matching images (early return)
- generate() errors without AI credentials
- generate() processes attachments end-to-end
- generate() --dry-run does not modify alt text
Register a real fake ability via wp_register_ability() using the WP
core test pattern of faking $wp_current_filter to satisfy
doing_action('wp_abilities_api_init') without triggering re-entrant
init calls from the registry singleton.
…xt-generate # Conflicts: # composer.lock # phpstan.neon.dist
Summary
wp ai alt-text generate— the plugin's first WP-CLI commandai/alt-text-generationability--batch-size,--dry-run,--force,--ids, and--delayflagsCloses #435
Test plan
wp ai alt-text generate --dry-runlists images missing alt text without making changeswp ai alt-text generate --batch-size=2processes images with progress bar, verify alt text saved in DBwp ai alt-text generate --ids=<id1>,<id2> --forceregenerates for specific images even if they already have alt text--delayflag adds visible pause between API callsAI use
I used Claude code to write this PR with a series of prompts. I tested the command manually and reviewed the code.