Skip to content

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

Merged
merged 3 commits into from
Aug 11, 2025

Conversation

SebastianWiz
Copy link
Contributor

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:

  • Replaced the emoji star with a single SVG star. The SVG is from Feather, an open-source icon library.
  • Added Customization options that allows the user to:
    • Enable the display of empty stars
    • Customize the stars appearance (size, color and stroke width)

Quick demo of the changes: https://www.loom.com/share/591fd8930a5f476aa3c381ec8606b610

…ar with empty star display option for rating fields.
Copy link

coderabbitai bot commented Aug 8, 2025

Walkthrough

The 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

Cohort / File(s) Change Summary
SVG Star Rendering & Decoding for Rating Fields
gp-entry-blocks/gpeb-display-stars-for-rating-fields.php
Replaces character-based stars with configurable SVG-based stars for rating fields, adds a decoding function for SVGs, and hooks both features into entry content filters.

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
Loading

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 details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4eafadb and 61073fe.

📒 Files selected for processing (1)
  • gp-entry-blocks/gpeb-display-stars-for-rating-fields.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • gp-entry-blocks/gpeb-display-stars-for-rating-fields.php
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch seb/add/87220-empty-stars-rating-display

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Aug 8, 2025

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against 61073fe

Copy link

@coderabbitai coderabbitai bot left a 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 theming

If 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 it

If 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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6e5edf and 876439f.

📒 Files selected for processing (1)
  • gp-entry-blocks/gpeb-display-stars-for-rating-fields.php (1 hunks)

Copy link
Contributor

@saifsultanc saifsultanc left a 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.
@SebastianWiz SebastianWiz merged commit 453ad6a into master Aug 11, 2025
3 of 4 checks passed
@SebastianWiz SebastianWiz deleted the seb/add/87220-empty-stars-rating-display branch August 11, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants