From bd3f7471960306e402856cf3076e3ce2c7034370 Mon Sep 17 00:00:00 2001
From: Doeke Norg <doekenorg@gmail.com>
Date: Mon, 15 Jan 2024 15:06:42 +0100
Subject: [PATCH] Show all empty stars on empty rating

---
 readme.txt                             | 1 +
 templates/fields/field-survey-html.php | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/readme.txt b/readme.txt
index c5d805469f..bed8ccd3bc 100644
--- a/readme.txt
+++ b/readme.txt
@@ -26,6 +26,7 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h
 This release makes it easier to customize search results per-View instead of globally using code.
 
 * Fixed: Sorting the View by entry ID in ascending and descending order would yield the same result
+* Fixed: Survey fields without a rating would show a 1-star rating
 
 __Developer Updates:__
 
diff --git a/templates/fields/field-survey-html.php b/templates/fields/field-survey-html.php
index 0e02b4c5e9..096bbcae57 100644
--- a/templates/fields/field-survey-html.php
+++ b/templates/fields/field-survey-html.php
@@ -147,7 +147,9 @@
 		$choices = $field->field->choices;
 		$choice_values = wp_list_pluck( $choices, 'value', $gravityview->value );
 		$starred_index = array_search( $gravityview->value, $choice_values );
-		$star_a11y_label = sprintf( __( '%s (%d out of %d stars)', 'gk-gravityview'), $choice_text, ( $starred_index + 1 ), sizeof( $choice_values ) );
+		$star_a11y_label = $starred_index !== false
+			?sprintf( __( '%s (%d out of %d stars)', 'gk-gravityview'), $choice_text, $starred_index + 1, count( $choice_values ) )
+			: '';
 
 		/**
 		 * @action `gravityview/field/survey/rating-styles`
@@ -162,7 +164,7 @@
 		foreach ( $choices as $current_index => $choice_value ) {
 
 			// Have we already shown the last filled-in star?
-			$empty = ( $current_index > $starred_index );
+			$empty = ( $starred_index === false || $current_index > $starred_index );
 			$css_class = 'gv-field-survey-star-' . ( $empty ? 'empty' : 'filled' );
 
 			echo sprintf( '<span class="%s" title="%s"></span>', esc_attr( $css_class ), esc_attr( $choice_value['text'] ) );