File "class-acf-field-number.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/fields/class-acf-field-number.php
File size: 4.06 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!class_exists('acf_field_number')) {
    class acf_field_number extends acf_field
    {
        function initialize()
        {
            $this->name = 'number';
            $this->label = __('Number', 'acf');
            $this->defaults = array('default_value' => '', 'min' => '', 'max' => '', 'step' => '', 'placeholder' => '', 'prepend' => '', 'append' => '');
        }
        function render_field($field)
        {
            $atts = array();
            $keys = array('type', 'id', 'class', 'name', 'value', 'min', 'max', 'step', 'placeholder', 'pattern');
            $keys2 = array('readonly', 'disabled', 'required');
            $html = '';
            if (!$field['step']) {
                $field['step'] = 'any';
            }
            if ($field['prepend'] !== '') {
                $field['class'] .= ' acf-is-prepended';
                $html .= '<div class="acf-input-prepend">' . acf_esc_html($field['prepend']) . '</div>';
            }
            if ($field['append'] !== '') {
                $field['class'] .= ' acf-is-appended';
                $html .= '<div class="acf-input-append">' . acf_esc_html($field['append']) . '</div>';
            }
            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-input-wrap">' . acf_get_text_input($atts) . '</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' => 'text', 'name' => 'default_value'));
            acf_render_field_setting($field, array('label' => __('Placeholder Text', 'acf'), 'instructions' => __('Appears within the input', 'acf'), 'type' => 'text', 'name' => 'placeholder'));
            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_render_field_setting($field, array('label' => __('Minimum Value', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'min'));
            acf_render_field_setting($field, array('label' => __('Maximum Value', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'max'));
            acf_render_field_setting($field, array('label' => __('Step Size', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'step'));
        }
        function validate_value($valid, $value, $field, $input)
        {
            if (acf_str_exists(',', $value)) {
                $value = str_replace(',', '', $value);
            }
            if (!is_numeric($value)) {
                if (!empty($value)) {
                    $valid = __('Value must be a number', 'acf');
                }
                return $valid;
            }
            $value = floatval($value);
            if (is_numeric($field['min']) && $value < floatval($field['min'])) {
                $valid = sprintf(__('Value must be equal to or higher than %d', 'acf'), $field['min']);
            }
            if (is_numeric($field['max']) && $value > floatval($field['max'])) {
                $valid = sprintf(__('Value must be equal to or lower than %d', 'acf'), $field['max']);
            }
            return $valid;
        }
        function update_value($value, $post_id, $field)
        {
            if (empty($value)) {
                return $value;
            }
            if (acf_str_exists(',', $value)) {
                $value = str_replace(',', '', $value);
            }
            return $value;
        }
    }
    acf_register_field_type('acf_field_number');
}