From 876439f2fc260d8bdb254a93aaf00ed811dd1b97 Mon Sep 17 00:00:00 2001 From: Sebastian Pedersen Date: Fri, 8 Aug 2025 07:28:19 -0700 Subject: [PATCH 1/3] `gpeb-display-stars-for-rating-fields.php`: Added customizable SVG star with empty star display option for rating fields. --- .../gpeb-display-stars-for-rating-fields.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php b/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php index 833ec9375..8a32f78f5 100644 --- a/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php +++ b/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php @@ -4,16 +4,42 @@ * https://gravitywiz.com/documentation/gravity-forms-entry-blocks/ */ add_filter( 'gpeb_entry', function( $entry, $form ) { + + // Configure star settings + $config = [ + 'star_size' => '24', // Width/height of stars in pixels + 'star_color' => '#FFAC33', // Color of the stars + 'stroke_width' => '1.5', // Thickness of star outline + 'show_empty_stars' => false, // Whether to show empty stars + ]; + + $star_svg = ''; + foreach ( $form['fields'] as $field ) { if ( $field->get_input_type() === 'rating' ) { $selected_value = $entry[ $field->id ]; foreach ( $field->choices as $index => $choice ) { if ( $choice['value'] === $selected_value ) { - $entry[ $field->id ] = str_repeat( '⭐', $index + 1 ); - break 2; + $filled_stars = str_repeat(str_replace('id] = $filled_stars . $empty_stars; + break; } } } } return $entry; }, 10, 2 ); + +// Unescape HTML-encoded SVG content for rating fields +function decode_rating_field_svgs($content, $entry_form, $entry) { + foreach ($entry_form['fields'] as $field) { + if ($field->get_input_type() === 'rating' && isset($entry[$field->id]) && strpos($entry[$field->id], 'id], ENT_QUOTES), $entry[$field->id], $content); + } + } + return $content; +} +add_filter('gpeb_loop_entry_content', 'decode_rating_field_svgs', 10, 3); +add_filter('gpeb_view_entry_content', 'decode_rating_field_svgs', 10, 3); \ No newline at end of file From 4eafadb4aff2214a487ce4e43f74c326fe67b6b3 Mon Sep 17 00:00:00 2001 From: Sebastian Pedersen Date: Sat, 9 Aug 2025 23:27:00 -0700 Subject: [PATCH 2/3] `gpeb-display-stars-for-rating-fields.php`: Added customizable SVG star with empty star display option for rating fields. --- .../gpeb-display-stars-for-rating-fields.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php b/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php index 8a32f78f5..b2086f9ba 100644 --- a/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php +++ b/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php @@ -7,20 +7,24 @@ // Configure star settings $config = [ - 'star_size' => '24', // Width/height of stars in pixels + 'star_size' => 24, // Width/height of stars in pixels 'star_color' => '#FFAC33', // Color of the stars - 'stroke_width' => '1.5', // Thickness of star outline + 'stroke_width' => 1.5, // Thickness of star outline 'show_empty_stars' => false, // Whether to show empty stars ]; - $star_svg = ''; + $star_size = max( 1, (int) $config['star_size'] ); + $stroke_width = (float) $config['stroke_width']; + $star_color = sanitize_hex_color( $config['star_color'] ) ?: '#FFAC33'; + + $star_svg = ''; foreach ( $form['fields'] as $field ) { if ( $field->get_input_type() === 'rating' ) { $selected_value = $entry[ $field->id ]; foreach ( $field->choices as $index => $choice ) { if ( $choice['value'] === $selected_value ) { - $filled_stars = str_repeat(str_replace('id] = $filled_stars . $empty_stars; From 61073fe890cfbaac2ed9886a0974ae6bb037c68f Mon Sep 17 00:00:00 2001 From: Sebastian Pedersen Date: Sat, 9 Aug 2025 23:42:36 -0700 Subject: [PATCH 3/3] `gpeb-display-stars-for-rating-fields.php`: Added customizable SVG star with empty star display option for rating fields. --- .../gpeb-display-stars-for-rating-fields.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php b/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php index b2086f9ba..3804fca94 100644 --- a/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php +++ b/gp-entry-blocks/gpeb-display-stars-for-rating-fields.php @@ -37,13 +37,15 @@ }, 10, 2 ); // Unescape HTML-encoded SVG content for rating fields -function decode_rating_field_svgs($content, $entry_form, $entry) { - foreach ($entry_form['fields'] as $field) { - if ($field->get_input_type() === 'rating' && isset($entry[$field->id]) && strpos($entry[$field->id], 'id], ENT_QUOTES), $entry[$field->id], $content); +if ( ! function_exists( 'decode_rating_field_svgs' ) ) { + function decode_rating_field_svgs($content, $entry_form, $entry) { + foreach ($entry_form['fields'] as $field) { + if ($field->get_input_type() === 'rating' && isset($entry[$field->id]) && strpos($entry[$field->id], 'id]), $entry[$field->id], $content); + } } + return $content; } - return $content; } add_filter('gpeb_loop_entry_content', 'decode_rating_field_svgs', 10, 3); add_filter('gpeb_view_entry_content', 'decode_rating_field_svgs', 10, 3); \ No newline at end of file