CMB2_Type_Text_Datetime_Timestamp

CMB text_datetime_timestamp field type.

Defined (1)

The class is defined in the following location(s).

/includes/types/CMB2_Type_Text_Datetime_Timestamp.php  
  1. class CMB2_Type_Text_Datetime_Timestamp extends CMB2_Type_Picker_Base { 
  2.  
  3. public function render() { 
  4. $field = $this->field; 
  5.  
  6. $args = wp_parse_args( $this->args, array( 
  7. 'value' => $field->escaped_value(),  
  8. 'desc' => $this->_desc(),  
  9. 'datepicker' => array(),  
  10. 'timepicker' => array(),  
  11. ) ); 
  12.  
  13. if ( empty( $args['value'] ) ) { 
  14. $args['value'] = $field->escaped_value(); 
  15. // This will be used if there is a select_timezone set for this field 
  16. $tz_offset = $field->field_timezone_offset(); 
  17. if ( ! empty( $tz_offset ) ) { 
  18. $args['value'] -= $tz_offset; 
  19.  
  20. $has_good_value = ! empty( $args['value'] ) && ! is_array( $args['value'] ); 
  21.  
  22. $date_input = parent::render( $this->date_args( $args, $has_good_value ) ); 
  23. $time_input = parent::render( $this->time_args( $args, $has_good_value ) ); 
  24.  
  25. return $this->rendered( $date_input . "\n" . $time_input ); 
  26.  
  27. public function date_args( $args, $has_good_value ) { 
  28. $date_args = wp_parse_args( $args['datepicker'], array( 
  29. 'class' => 'cmb2-text-small cmb2-datepicker',  
  30. 'name' => $this->_name( '[date]' ),  
  31. 'id' => $this->_id( '_date' ),  
  32. 'value' => $has_good_value ? $this->field->get_timestamp_format( 'date_format', $args['value'] ) : '',  
  33. 'desc' => '',  
  34. ) ); 
  35.  
  36. $date_args['rendered'] = true; 
  37.  
  38. // Let's get the date-format, and set it up as a data attr for the field. 
  39. return $this->parse_picker_options( 'date', $date_args ); 
  40.  
  41. public function time_args( $args, $has_good_value ) { 
  42. $time_args = wp_parse_args( $args['timepicker'], array( 
  43. 'class' => 'cmb2-timepicker text-time',  
  44. 'name' => $this->_name( '[time]' ),  
  45. 'id' => $this->_id( '_time' ),  
  46. 'value' => $has_good_value ? $this->field->get_timestamp_format( 'time_format', $args['value'] ) : '',  
  47. 'desc' => $args['desc'],  
  48. 'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-datetimepicker' ),  
  49. ) ); 
  50.  
  51. $time_args['rendered'] = true; 
  52.  
  53. // Let's get the time-format, and set it up as a data attr for the field. 
  54. return $this->parse_picker_options( 'time', $time_args ); 
  55.