| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. |
| 2 |
/** |
| 3 |
* |
| 4 |
* Field: number |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
* |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'ADMINIFY_Field_number' ) ) { |
| 11 |
class ADMINIFY_Field_number extends ADMINIFY_Fields { |
| 12 |
|
| 13 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 14 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 15 |
} |
| 16 |
|
| 17 |
public function render() { |
| 18 |
|
| 19 |
$args = wp_parse_args( $this->field, array( |
| 20 |
'unit' => '', |
| 21 |
) ); |
| 22 |
|
| 23 |
echo $this->field_before(); |
| 24 |
echo '<div class="adminify--wrap">'; |
| 25 |
echo '<input type="number" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes( array( 'class' => 'adminify-input-number' ) ) .' step="any" />'; |
| 26 |
echo ( ! empty( $args['unit'] ) ) ? '<span class="adminify--unit">'. esc_attr( $args['unit'] ) .'</span>' : ''; |
| 27 |
echo '</div>'; |
| 28 |
echo $this->field_after(); |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
public function output() { |
| 33 |
|
| 34 |
$output = ''; |
| 35 |
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] ); |
| 36 |
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; |
| 37 |
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width'; |
| 38 |
$unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px'; |
| 39 |
|
| 40 |
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) { |
| 41 |
foreach ( $elements as $key_property => $element ) { |
| 42 |
if ( is_numeric( $key_property ) ) { |
| 43 |
if ( $mode ) { |
| 44 |
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $unit . $important .';}'; |
| 45 |
} |
| 46 |
break; |
| 47 |
} else { |
| 48 |
$output .= $element .'{'. $key_property .':'. $this->value . $unit . $important .'}'; |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
$this->parent->output_css .= $output; |
| 54 |
|
| 55 |
return $output; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
} |
| 61 |
|