22 lines
1.4 KiB
PHP
22 lines
1.4 KiB
PHP
<?php
|
|
if (!defined('ABSPATH')) exit;
|
|
class WMF_Field_Rating extends WMF_Field_Base {
|
|
public $type='rating'; public $label='Bewertung (Sterne)'; public $icon='dashicons-star-filled'; public $category='auswahl';
|
|
public function defaults() { return array_merge(parent::defaults(),array('max_stars'=>'5','icon'=>'star')); }
|
|
public function render($field,$value='') {
|
|
$max=intval($field['max_stars']??5); ?>
|
|
<div class="<?php echo esc_attr($this->wrapper_classes($field)); ?>"<?php echo $this->conditional_attrs($field); ?> data-field-id="<?php echo esc_attr($field['id']); ?>">
|
|
<?php $this->render_label($field); ?>
|
|
<div class="wmf-rating" data-max="<?php echo $max; ?>">
|
|
<?php for($i=1;$i<=$max;$i++): ?>
|
|
<button type="button" class="wmf-star <?php echo $i<=intval($value)?'active':''; ?>" data-value="<?php echo $i; ?>" aria-label="<?php echo $i; ?> Stern">★</button>
|
|
<?php endfor; ?>
|
|
<input type="hidden" name="wmf_fields[<?php echo esc_attr($field['id']); ?>]" value="<?php echo esc_attr($value); ?>" class="wmf-rating-value">
|
|
</div>
|
|
<?php $this->render_description($field); ?>
|
|
<span class="wmf-field-error-msg"></span>
|
|
</div><?php
|
|
}
|
|
public function sanitize($v,$f) { return max(0,min(intval($f['max_stars']??5),intval($v))); }
|
|
}
|