datetime.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: datetime
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_datetime' ) ) {
  11. class CSF_Field_datetime extends CSF_Fields {
  12. public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
  13. parent::__construct( $field, $value, $unique, $where, $parent );
  14. }
  15. public function render() {
  16. $defaults = array(
  17. 'allowInput' => true,
  18. );
  19. $settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
  20. if ( ! isset( $settings['noCalendar'] ) ) {
  21. $defaults['dateFormat'] = 'm/d/Y';
  22. }
  23. $settings = wp_parse_args( $settings, $defaults );
  24. echo $this->field_before();
  25. if ( ! empty( $this->field['from_to'] ) ) {
  26. $args = wp_parse_args( $this->field, array(
  27. 'text_from' => esc_html__( 'From', 'sakurairo_csf' ),
  28. 'text_to' => esc_html__( 'To', 'sakurairo_csf' ),
  29. ) );
  30. $value = wp_parse_args( $this->value, array(
  31. 'from' => '',
  32. 'to' => '',
  33. ) );
  34. echo '<label class="csf--from">'. esc_attr( $args['text_from'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[from]' ) ) .'" value="'. esc_attr( $value['from'] ) .'"'. $this->field_attributes() .' data-type="from" /></label>';
  35. echo '<label class="csf--to">'. esc_attr( $args['text_to'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[to]' ) ) .'" value="'. esc_attr( $value['to'] ) .'"'. $this->field_attributes() .' data-type="to" /></label>';
  36. } else {
  37. echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
  38. }
  39. echo '<div class="csf-datetime-settings" data-settings="'. esc_attr( json_encode( $settings ) ) .'"></div>';
  40. echo $this->field_after();
  41. }
  42. }
  43. }