| @@ -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: date |
| 5 | 6 | * |
| @@ -4,61 +5,58 @@ | ||
| 4 | 5 | * Field: date |
| 5 | 6 | * |
| 6 | 7 | * @since 1.0.0 |
| 7 | 8 | * @version 1.0.0 |
| 8 | - * | |
| 9 | 9 | */ |
| 10 | 10 | if ( ! class_exists( 'ADMINIFY_Field_date' ) ) { |
| 11 | - class ADMINIFY_Field_date extends ADMINIFY_Fields { | |
| 11 | + class ADMINIFY_Field_date 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 | + $default_settings = [ | |
| 19 | + 'dateFormat' => 'mm/dd/yy', | |
| 20 | + ]; | |
| 18 | 21 | |
| 19 | - $default_settings = array( | |
| 20 | - 'dateFormat' => 'mm/dd/yy', | |
| 21 | - ); | |
| 22 | + $settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : []; | |
| 23 | + $settings = wp_parse_args( $settings, $default_settings ); | |
| 22 | 24 | |
| 23 | - $settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array(); | |
| 24 | - $settings = wp_parse_args( $settings, $default_settings ); | |
| 25 | + echo wp_kses_post( $this->field_before() ); | |
| 25 | 26 | |
| 26 | - echo wp_kses_post( $this->field_before() ); | |
| 27 | + if ( ! empty( $this->field['from_to'] ) ) { | |
| 28 | + $args = wp_parse_args( | |
| 29 | + $this->field, | |
| 30 | + [ | |
| 31 | + 'text_from' => esc_html__( 'From', 'adminify' ), | |
| 32 | + 'text_to' => esc_html__( 'To', 'adminify' ), | |
| 33 | + ] | |
| 34 | + ); | |
| 27 | 35 | |
| 28 | - if ( ! empty( $this->field['from_to'] ) ) { | |
| 36 | + $value = wp_parse_args( | |
| 37 | + $this->value, | |
| 38 | + [ | |
| 39 | + 'from' => '', | |
| 40 | + 'to' => '', | |
| 41 | + ] | |
| 42 | + ); | |
| 29 | 43 | |
| 30 | - $args = wp_parse_args( $this->field, array( | |
| 31 | - 'text_from' => esc_html__( 'From', 'adminify' ), | |
| 32 | - 'text_to' => esc_html__( 'To', 'adminify' ), | |
| 33 | - ) ); | |
| 44 | + echo '<label class="adminify--from">' . esc_attr( $args['text_from'] ) . ' <input type="text" name="' . esc_attr( $this->field_name( '[from]' ) ) . '" value="' . esc_attr( $value['from'] ) . '"' . wp_kses_post( $this->field_attributes() ) . '/></label>'; | |
| 45 | + echo '<label class="adminify--to">' . esc_attr( $args['text_to'] ) . ' <input type="text" name="' . esc_attr( $this->field_name( '[to]' ) ) . '" value="' . esc_attr( $value['to'] ) . '"' . wp_kses_post( $this->field_attributes() ) . '/></label>'; | |
| 46 | + } else { | |
| 47 | + echo '<input type="text" name="' . esc_attr( $this->field_name() ) . '" value="' . esc_attr( $this->value ) . '"' . wp_kses_post( $this->field_attributes() ) . '/>'; | |
| 48 | + } | |
| 34 | 49 | |
| 35 | - $value = wp_parse_args( $this->value, array( | |
| 36 | - 'from' => '', | |
| 37 | - 'to' => '', | |
| 38 | - ) ); | |
| 50 | + echo '<div class="adminify-date-settings" data-settings="' . esc_attr( json_encode( $settings ) ) . '"></div>'; | |
| 39 | 51 | |
| 40 | - echo '<label class="adminify--from">'. esc_attr( $args['text_from'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[from]' ) ) .'" value="'. esc_attr( $value['from'] ) .'"'. $this->field_attributes() .'/></label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- field_attributes() escapes each attribute via esc_attr() | |
| 41 | - echo '<label class="adminify--to">'. esc_attr( $args['text_to'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[to]' ) ) .'" value="'. esc_attr( $value['to'] ) .'"'. $this->field_attributes() .'/></label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- field_attributes() escapes each attribute via esc_attr() | |
| 52 | + echo wp_kses_post( $this->field_after() ); | |
| 53 | + } | |
| 42 | 54 | |
| 43 | - } else { | |
| 55 | + public function enqueue() { | |
| 56 | + if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) { | |
| 57 | + wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 58 | + } | |
| 59 | + } | |
| 44 | 60 | |
| 45 | - echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- field_attributes() escapes each attribute via esc_attr() | |
| 46 | - | |
| 47 | - } | |
| 48 | - | |
| 49 | - echo '<div class="adminify-date-settings" data-settings="'. esc_attr( wp_json_encode( $settings ) ) .'"></div>'; | |
| 50 | - | |
| 51 | - echo wp_kses_post( $this->field_after() ); | |
| 52 | - | |
| 53 | - } | |
| 54 | - | |
| 55 | - public function enqueue() { | |
| 56 | - | |
| 57 | - if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) { | |
| 58 | - wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 59 | - } | |
| 60 | - | |
| 61 | - } | |
| 62 | - | |
| 63 | - } | |
| 61 | + } | |
| 64 | 62 | } |