Add wp icon and wp icon collection commands - #648
Conversation
WordPress 7.1 introduced an Icons API where SVG icons are registered in code with `wp_register_icon()` and grouped into collections registered with `wp_register_icon_collection()`. Like font collections, they are registry-based and only exist for the duration of a request, so the new commands read and render them rather than creating or deleting them. `wp icon list` supports filtering by collection and searching names and labels, `wp icon get` exposes the registered SVG markup and the file an icon is loaded from, and `wp icon render` applies the same sizing and accessibility attributes that WordPress applies on the front end, so the markup can be piped straight into a template. Both commands abort on WordPress < 7.1 via `before_invoke`. The Icons API is not covered by the WordPress stubs yet, so the PHPStan entries for the unknown symbols use `reportUnmatched` to avoid becoming errors themselves once the stubs catch up. Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gg5xvmNbnSSpXzmGmWu1xh
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughAdded WordPress 7.1-gated WP-CLI commands for listing, retrieving, checking, and rendering registered icons and icon collections. Added formatter support, SVG validation, compatibility configuration, and acceptance-test coverage. ChangesIcon command support
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to This PR adds CLI support for managing registered SVG icons and collections; no actionable merge-blocking risk remains based on the current evidence. Sequence Diagram(s)sequenceDiagram
participant CLI
participant Icon_Command
participant IconsRegistry
participant wp_get_icon
CLI->>Icon_Command: render icon with size, class, and label
Icon_Command->>IconsRegistry: retrieve registered icon
Icon_Command->>wp_get_icon: render icon SVG
wp_get_icon-->>Icon_Command: SVG markup
Icon_Command-->>CLI: output rendered SVG
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 3 files. (5 skipped: 5 unsupported.) ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
src/Icon_Command.php:306
- In SVG, the attribute is case-sensitive and should be
viewBox, notviewbox(the current example markup is invalid SVG/XML as written).
* <svg aria-hidden="true" focusable="false" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24">
Add new WP-CLI commands to manage WordPress SVG icons and icon collections, which were introduced in WordPress 7.0 and 7.1.
Summary
This adds comprehensive command-line support for the WordPress Icons API through two new command groups:
wp iconandwp icon collection. These commands allow users to list, inspect, and render registered SVG icons and their collections.Key Changes
Icon_Command.php: New command class with four subcommands:
wp icon list- List registered icons with filtering by collection and search termwp icon get- Display detailed information about a specific iconwp icon is-registered- Check if an icon is registered (useful in scripts)wp icon render- Render an icon's SVG markup with customizable size, CSS classes, and accessible labelsIcon_Collection_Command.php: New command class with three subcommands:
wp icon collection list- List all registered icon collections with icon countswp icon collection get- Display details about a specific collectionwp icon collection is-registered- Check if a collection is registeredFeature tests: Comprehensive Behat test coverage for both command groups, including:
Configuration updates:
entity-command.phpwith version check (WordPress 7.1+)composer.jsonfor documentation generationphpstan.neon.distto suppress compatibility warnings for the new Icons APIphpcs.xml.distto exclude new command files from certain checksImplementation Details
https://claude.ai/code/session_01Gg5xvmNbnSSpXzmGmWu1xh
Summary by CodeRabbit
New Features
Tests