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 833ec937..3804fca9 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,48 @@ * 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_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 ) { - $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 +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; + } +} +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