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