4
4
* https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
5
5
*/
6
6
add_filter ( 'gpeb_entry ' , function ( $ entry , $ form ) {
7
+
8
+ // Configure star settings
9
+ $ config = [
10
+ 'star_size ' => 24 , // Width/height of stars in pixels
11
+ 'star_color ' => '#FFAC33 ' , // Color of the stars
12
+ 'stroke_width ' => 1.5 , // Thickness of star outline
13
+ 'show_empty_stars ' => false , // Whether to show empty stars
14
+ ];
15
+
16
+ $ star_size = max ( 1 , (int ) $ config ['star_size ' ] );
17
+ $ stroke_width = (float ) $ config ['stroke_width ' ];
18
+ $ star_color = sanitize_hex_color ( $ config ['star_color ' ] ) ?: '#FFAC33 ' ;
19
+
20
+ $ star_svg = '<svg xmlns="http://www.w3.org/2000/svg" width=" ' . esc_attr ( $ star_size ) . '" height=" ' . esc_attr ( $ star_size ) . '" viewBox="0 0 24 24" stroke=" ' . esc_attr ( $ star_color ) . '" stroke-width=" ' . esc_attr ( $ stroke_width ) . '" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg> ' ;
21
+
7
22
foreach ( $ form ['fields ' ] as $ field ) {
8
23
if ( $ field ->get_input_type () === 'rating ' ) {
9
24
$ selected_value = $ entry [ $ field ->id ];
10
25
foreach ( $ field ->choices as $ index => $ choice ) {
11
26
if ( $ choice ['value ' ] === $ selected_value ) {
12
- $ entry [ $ field ->id ] = str_repeat ( '⭐ ' , $ index + 1 );
13
- break 2 ;
27
+ $ filled_stars = str_repeat (str_replace ('<svg ' , '<svg fill=" ' . esc_attr ( $ star_color ) . '" class="gpeb-filled-star" ' , $ star_svg ), $ index + 1 );
28
+ $ empty_stars = $ config ['show_empty_stars ' ] ? str_repeat (str_replace ('<svg ' , '<svg fill="none" class="gpeb-outline-star" ' , $ star_svg ), 5 - ($ index + 1 )) : '' ;
29
+
30
+ $ entry [$ field ->id ] = $ filled_stars . $ empty_stars ;
31
+ break ;
14
32
}
15
33
}
16
34
}
17
35
}
18
36
return $ entry ;
19
37
}, 10 , 2 );
38
+
39
+ // Unescape HTML-encoded SVG content for rating fields
40
+ if ( ! function_exists ( 'decode_rating_field_svgs ' ) ) {
41
+ function decode_rating_field_svgs ($ content , $ entry_form , $ entry ) {
42
+ foreach ($ entry_form ['fields ' ] as $ field ) {
43
+ if ($ field ->get_input_type () === 'rating ' && isset ($ entry [$ field ->id ]) && strpos ($ entry [$ field ->id ], '<svg ' ) !== false ) {
44
+ $ content = str_replace (esc_html ($ entry [$ field ->id ]), $ entry [$ field ->id ], $ content );
45
+ }
46
+ }
47
+ return $ content ;
48
+ }
49
+ }
50
+ add_filter ('gpeb_loop_entry_content ' , 'decode_rating_field_svgs ' , 10 , 3 );
51
+ add_filter ('gpeb_view_entry_content ' , 'decode_rating_field_svgs ' , 10 , 3 );
0 commit comments