| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; } // Cannot access directly. |
| 3 |
/** |
| 4 |
* |
| 5 |
* Field: date |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'DarkifyField_date' ) ) { |
| 11 |
class DarkifyField_date extends DarkifyFields { |
| 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 |
$default_settings = array( |
| 20 |
'dateFormat' => 'mm/dd/yy', |
| 21 |
); |
| 22 |
|
| 23 |
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array(); |
| 24 |
$settings = wp_parse_args( $settings, $default_settings ); |
| 25 |
|
| 26 |
echo wp_kses_post( $this->field_before() ); |
| 27 |
|
| 28 |
if ( ! empty( $this->field['from_to'] ) ) { |
| 29 |
|
| 30 |
$args = wp_parse_args( |
| 31 |
$this->field, |
| 32 |
array( |
| 33 |
'text_from' => esc_html__( 'From', 'darkify' ), |
| 34 |
'text_to' => esc_html__( 'To', 'darkify' ), |
| 35 |
) |
| 36 |
); |
| 37 |
|
| 38 |
$value = wp_parse_args( |
| 39 |
$this->value, |
| 40 |
array( |
| 41 |
'from' => '', |
| 42 |
'to' => '', |
| 43 |
) |
| 44 |
); |
| 45 |
|
| 46 |
echo '<label class="darkify--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>'; |
| 47 |
echo '<label class="darkify--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>'; |
| 48 |
|
| 49 |
} else { |
| 50 |
|
| 51 |
echo '<input type="text" name="' . esc_attr( $this->field_name() ) . '" value="' . esc_attr( $this->value ) . '"' . wp_kses_post( $this->field_attributes() ) . '/>'; |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
echo '<div class="darkify-date-settings" data-settings="' . esc_attr( wp_json_encode( $settings ) ) . '"></div>'; |
| 56 |
|
| 57 |
echo wp_kses_post( $this->field_after() ); |
| 58 |
} |
| 59 |
|
| 60 |
public function enqueue() { |
| 61 |
|
| 62 |
if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) { |
| 63 |
wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|