|
7 | 7 |
|
8 | 8 | // Configure star settings |
9 | 9 | $config = [ |
10 | | - 'star_size' => '24', // Width/height of stars in pixels |
| 10 | + 'star_size' => 24, // Width/height of stars in pixels |
11 | 11 | 'star_color' => '#FFAC33', // Color of the stars |
12 | | - 'stroke_width' => '1.5', // Thickness of star outline |
| 12 | + 'stroke_width' => 1.5, // Thickness of star outline |
13 | 13 | 'show_empty_stars' => false, // Whether to show empty stars |
14 | 14 | ]; |
15 | 15 |
|
16 | | - $star_svg = '<svg xmlns="http://www.w3.org/2000/svg" width="' . $config['star_size'] . '" height="' . $config['star_size'] . '" viewBox="0 0 24 24" stroke="' . $config['star_color'] . '" stroke-width="' . $config['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>'; |
| 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>'; |
17 | 21 |
|
18 | 22 | foreach ( $form['fields'] as $field ) { |
19 | 23 | if ( $field->get_input_type() === 'rating' ) { |
20 | 24 | $selected_value = $entry[ $field->id ]; |
21 | 25 | foreach ( $field->choices as $index => $choice ) { |
22 | 26 | if ( $choice['value'] === $selected_value ) { |
23 | | - $filled_stars = str_repeat(str_replace('<svg ', '<svg fill="' . $config['star_color'] . '" class="gpeb-filled-star" ', $star_svg), $index + 1); |
| 27 | + $filled_stars = str_repeat(str_replace('<svg ', '<svg fill="' . esc_attr( $star_color ) . '" class="gpeb-filled-star" ', $star_svg), $index + 1); |
24 | 28 | $empty_stars = $config['show_empty_stars'] ? str_repeat(str_replace('<svg ', '<svg fill="none" class="gpeb-outline-star" ', $star_svg), 5 - ($index + 1)) : ''; |
25 | 29 |
|
26 | 30 | $entry[$field->id] = $filled_stars . $empty_stars; |
|
0 commit comments