date.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: date
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_date' ) ) {
  11. class CSF_Field_date 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. $default_settings = array(
  17. 'dateFormat' => 'mm/dd/yy',
  18. );
  19. $settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
  20. $settings = wp_parse_args( $settings, $default_settings );
  21. echo $this->field_before();
  22. if ( ! empty( $this->field['from_to'] ) ) {
  23. $args = wp_parse_args( $this->field, array(
  24. 'text_from' => esc_html__( 'From', 'sakurairo_csf' ),
  25. 'text_to' => esc_html__( 'To', 'sakurairo_csf' ),
  26. ) );
  27. $value = wp_parse_args( $this->value, array(
  28. 'from' => '',
  29. 'to' => '',
  30. ) );
  31. 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() .'/></label>';
  32. 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() .'/></label>';
  33. } else {
  34. echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
  35. }
  36. echo '<div class="csf-date-settings" data-settings="'. esc_attr( json_encode( $settings ) ) .'"></div>';
  37. echo $this->field_after();
  38. }
  39. public function enqueue() {
  40. if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) {
  41. wp_enqueue_script( 'jquery-ui-datepicker' );
  42. }
  43. }
  44. }
  45. }