-
Notifications
You must be signed in to change notification settings - Fork 93
gpeb-display-stars-for-rating-fields.php
: Added customizable SVG star with empty star display option for rating fields.
#1143
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
gpeb-display-stars-for-rating-fields.php
: Added customizable SVG star with empty star display option for rating fields.
#1143
Conversation
…ar with empty star display option for rating fields.
WalkthroughThe code now renders rating fields using configurable SVG-based stars instead of repeated star characters. It introduces a configuration array for star appearance, updates field values to SVG markup based on ratings, and adds a function to decode HTML-encoded SVGs for proper display. Relevant filters are updated to apply these changes. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant EntryDisplay
participant SVGRenderer
participant SVGDecoder
User->>EntryDisplay: View entry with rating field
EntryDisplay->>SVGRenderer: Render rating field as SVG stars
SVGRenderer-->>EntryDisplay: Return SVG star markup
EntryDisplay->>SVGDecoder: Decode HTML-encoded SVGs in content
SVGDecoder-->>EntryDisplay: Return decoded content
EntryDisplay-->>User: Display entry with SVG stars
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
🧹 Nitpick comments (3)
gp-entry-blocks/gpeb-display-stars-for-rating-fields.php (3)
16-16
: Optional: prefer CSS color via currentColor for simpler themingIf you’re open to CSS-driven theming, set stroke="currentColor" on the base SVG and control colors with the wrapper/container class. Keep fill/color on the variants as you do now.
-$star_svg = '<svg ... stroke="' . esc_attr( $star_color ) . '" ...> +$star_svg = '<svg ... stroke="currentColor" ...>Then set the color via CSS on .gpeb-rating, and keep the inline fill for filled vs outline variants as-is. This makes per-context color overrides trivial without regenerating the SVG string.
44-45
: Hook names look correct; update callback if you rename itIf you adopt the function prefixing, point the filters at the new name.
-add_filter('gpeb_loop_entry_content', 'decode_rating_field_svgs', 10, 3); -add_filter('gpeb_view_entry_content', 'decode_rating_field_svgs', 10, 3); +add_filter( 'gpeb_loop_entry_content', 'gpeb_decode_rating_field_svgs', 10, 3 ); +add_filter( 'gpeb_view_entry_content', 'gpeb_decode_rating_field_svgs', 10, 3 );
7-17
: General: small robustness and DX tweaks
- Consider exposing an additional config key 'total_stars' to override count($field->choices) when needed (e.g., legacy entries with mismatched choices). You can default to count($field->choices) when not provided.
- Optionally add an 'empty_star_stroke_color' to differentiate outline color from filled color.
- Add brief attribution comment for Feather icon in the header if your project requires third‑party asset attribution.
Happy to update the PR with the above changes if you want me to push a patch.
Also applies to: 23-27, 36-45
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.
Just recommend some sanitization as suggested by coderabbit. Then, S&M!
…ar with empty star display option for rating fields.
…ar with empty star display option for rating fields.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/3021474440/87220?viewId=8172236
Summary
This PR addresses a feature request that would allow the user to display empty stars after the filled stars, as well as being able to change the color.
Changes:
Quick demo of the changes: https://www.loom.com/share/591fd8930a5f476aa3c381ec8606b610