File "class-acf-field-range.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/fields/class-acf-field-range.php
File
size: 3.46 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
if (!class_exists('acf_field_range')) {
class acf_field_range extends acf_field_number
{
function initialize()
{
$this->name = 'range';
$this->label = __('Range', 'acf');
$this->defaults = array('default_value' => '', 'min' => '', 'max' => '', 'step' => '', 'prepend' => '', 'append' => '');
}
function render_field($field)
{
$atts = array();
$keys = array('type', 'id', 'class', 'name', 'value', 'min', 'max', 'step');
$keys2 = array('readonly', 'disabled', 'required');
$html = '';
if (!$field['step']) {
$field['step'] = 1;
}
if (!$field['min']) {
$field['min'] = 0;
}
if (!$field['max']) {
$field['max'] = 100;
}
if (!is_numeric($field['value'])) {
$field['value'] = 0;
}
$field['value'] = max($field['value'], $field['min']);
$field['value'] = min($field['value'], $field['max']);
foreach ($keys as $k) {
if (isset($field[$k])) {
$atts[$k] = $field[$k];
}
}
foreach ($keys2 as $k) {
if (!empty($field[$k])) {
$atts[$k] = $k;
}
}
$atts = acf_clean_atts($atts);
$html .= '<div class="acf-range-wrap">';
if ($field['prepend'] !== '') {
$html .= '<div class="acf-prepend">' . acf_esc_html($field['prepend']) . '</div>';
}
$html .= acf_get_text_input($atts);
$len = max(strlen(strval($field['min'])), strlen(strval($field['max'])));
if (floatval($atts['step']) < 1) {
$len += strlen(strval($field['step'])) - 1.5;
}
$html .= acf_get_text_input(array('type' => 'number', 'id' => $atts['id'] . '-alt', 'value' => $atts['value'], 'step' => $atts['step'], 'style' => 'width: ' . (1.8 + $len * 0.7) . 'em;'));
if ($field['append'] !== '') {
$html .= '<div class="acf-append">' . acf_esc_html($field['append']) . '</div>';
}
$html .= '</div>';
echo $html;
}
function render_field_settings($field)
{
acf_render_field_setting($field, array('label' => __('Default Value', 'acf'), 'instructions' => __('Appears when creating a new post', 'acf'), 'type' => 'number', 'name' => 'default_value'));
acf_render_field_setting($field, array('label' => __('Minimum Value', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'min', 'placeholder' => '0'));
acf_render_field_setting($field, array('label' => __('Maximum Value', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'max', 'placeholder' => '100'));
acf_render_field_setting($field, array('label' => __('Step Size', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'step', 'placeholder' => '1'));
acf_render_field_setting($field, array('label' => __('Prepend', 'acf'), 'instructions' => __('Appears before the input', 'acf'), 'type' => 'text', 'name' => 'prepend'));
acf_render_field_setting($field, array('label' => __('Append', 'acf'), 'instructions' => __('Appears after the input', 'acf'), 'type' => 'text', 'name' => 'append'));
}
}
acf_register_field_type('acf_field_range');
}