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