| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 3 |
|
| 4 |
if ( empty( $data['values'] ) || empty( $data['name'] ) ) { |
| 5 |
return; |
| 6 |
} |
| 7 |
|
| 8 |
if ( ! isset( $data['value'] ) ) { |
| 9 |
$data['value'] = key( $data['values'] ); |
| 10 |
} |
| 11 |
|
| 12 |
if ( empty( $data['current_label'] ) ) { |
| 13 |
$data['current_label'] = __( 'Current value:', 'imagify' ); |
| 14 |
} |
| 15 |
|
| 16 |
if ( ! isset( $data['values'][ $data['value'] ] ) ) { |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
$list_id = str_replace( [ '[', ']' ], [ '-', '' ], $data['name'] ); |
| 21 |
$list_id = 'imagify-' . $list_id . '-selector-list'; |
| 22 |
?> |
| 23 |
|
| 24 |
<div class="imagify-selector"> |
| 25 |
<span class="hide-if-js"> |
| 26 |
<?php echo esc_html( $data['current_label'] ); ?> |
| 27 |
<span class="imagify-selector-current-value-info"><?php echo $data['values'][ $data['value'] ]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span> |
| 28 |
</span> |
| 29 |
|
| 30 |
<button aria-controls="<?php echo esc_attr( $list_id ); ?>" type="button" class="button imagify-button-clean hide-if-no-js imagify-selector-button"> |
| 31 |
<span class="imagify-selector-current-value-info"><?php echo $data['values'][ $data['value'] ]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span> |
| 32 |
</button> |
| 33 |
|
| 34 |
<ul id="<?php echo esc_attr( $list_id ); ?>" role="listbox" aria-orientation="vertical" aria-hidden="true" class="imagify-selector-list hide-if-no-js"> |
| 35 |
<?php |
| 36 |
foreach ( $data['values'] as $val => $label ) { |
| 37 |
$input_id = $list_id . '-' . sanitize_html_class( $val ); |
| 38 |
?> |
| 39 |
<li class="imagify-selector-choice<?php echo $val === $data['value'] ? ' imagify-selector-current-value" aria-current="true' : ''; ?>" role="option"> |
| 40 |
<input type="radio" name="<?php echo esc_attr( $data['name'] ); ?>" value="<?php echo esc_attr( $val ); ?>" id="<?php echo esc_attr( $input_id ); ?>" <?php checked( $val, $data['value'] ); ?> class="screen-reader-text"> |
| 41 |
<label for="<?php echo esc_attr( $input_id ); ?>"><?php echo $label; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></label> |
| 42 |
</li> |
| 43 |
<?php |
| 44 |
} |
| 45 |
?> |
| 46 |
</ul> |
| 47 |
</div> |
| 48 |
|