acf_field_date_picker

The Advanced Custom Fields acf field date picker class.

Defined (1)

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

/core/fields/date_picker/date_picker.php  
  1. class acf_field_date_picker extends acf_field 
  2.  
  3. /** 
  4. * __construct 
  5. * Set name / label needed for actions / filters 
  6. * @since 3.6 
  7. * @date 23/01/13 
  8. */ 
  9.  
  10. function __construct() 
  11. // vars 
  12. $this->name = 'date_picker'; 
  13. $this->label = __("Date Picker", 'acf'); 
  14. $this->category = __("jQuery", 'acf'); 
  15. $this->defaults = array( 
  16. 'date_format' => 'yymmdd',  
  17. 'display_format' => 'dd/mm/yy',  
  18. 'first_day' => 1, // monday 
  19. ); 
  20.  
  21.  
  22. // actions 
  23. add_action('init', array($this, 'init')); 
  24.  
  25.  
  26. // do not delete! 
  27. parent::__construct(); 
  28.  
  29.  
  30. /** 
  31. * init 
  32. * This function is run on the 'init' action to set the field's $l10n data. Before the init action,  
  33. * access to the $wp_locale variable is not possible. 
  34. * @type action (init) 
  35. * @date 3/09/13 
  36. * @param N/A 
  37. * @return N/A 
  38. */ 
  39.  
  40. function init() 
  41. global $wp_locale; 
  42.  
  43. $this->l10n = array( 
  44. 'closeText' => __( 'Done', 'acf' ),  
  45. 'currentText' => __( 'Today', 'acf' ),  
  46. 'monthNames' => array_values( $wp_locale->month ),  
  47. 'monthNamesShort' => array_values( $wp_locale->month_abbrev ),  
  48. 'monthStatus' => __( 'Show a different month', 'acf' ),  
  49. 'dayNames' => array_values( $wp_locale->weekday ),  
  50. 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ),  
  51. 'dayNamesMin' => array_values( $wp_locale->weekday_initial ),  
  52. 'isRTL' => isset($wp_locale->is_rtl) ? $wp_locale->is_rtl : false,  
  53. ); 
  54.  
  55.  
  56. /** 
  57. * create_field() 
  58. * Create the HTML interface for your field 
  59. * @param $field - an array holding all the field's data 
  60. * @type action 
  61. * @since 3.6 
  62. * @date 23/01/13 
  63. */ 
  64.  
  65. function create_field( $field ) 
  66. // make sure it's not blank 
  67. if( !$field['date_format'] ) 
  68. $field['date_format'] = 'yymmdd'; 
  69. if( !$field['display_format'] ) 
  70. $field['display_format'] = 'dd/mm/yy'; 
  71.  
  72.  
  73. // html 
  74. echo '<div class="acf-date_picker" data-save_format="' . $field['date_format'] . '" data-display_format="' . $field['display_format'] . '" data-first_day="' . $field['first_day'] . '">'; 
  75. echo '<input type="hidden" value="' . $field['value'] . '" name="' . $field['name'] . '" class="input-alt" />'; 
  76. echo '<input type="text" value="" class="input" />'; 
  77. echo '</div>'; 
  78.  
  79.  
  80. /** 
  81. * create_options() 
  82. * Create extra options for your field. This is rendered when editing a field. 
  83. * The value of $field['name'] can be used (like bellow) to save extra data to the $field 
  84. * @type action 
  85. * @since 3.6 
  86. * @date 23/01/13 
  87. * @param $field - an array holding all the field's data 
  88. */ 
  89.  
  90. function create_options( $field ) 
  91. // global 
  92. global $wp_locale; 
  93.  
  94.  
  95. // vars 
  96. $key = $field['name']; 
  97.  
  98. ?> 
  99. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  100. <td class="label"> 
  101. <label><?php _e("Save format", 'acf'); ?></label> 
  102. <p class="description"><?php _e("This format will determine the value saved to the database and returned via the API", 'acf'); ?></p> 
  103. <p><?php _e("\"yymmdd\" is the most versatile save format. Read more about", 'acf'); ?> <a href="http://docs.jquery.com/UI/Datepicker/formatDate"><?php _e("jQuery date formats", 'acf'); ?></a></p> 
  104. </td> 
  105. <td> 
  106. <?php  
  107. do_action('acf/create_field', array( 
  108. 'type' => 'text',  
  109. 'name' => 'fields[' .$key.'][date_format]',  
  110. 'value' => $field['date_format'],  
  111. )); 
  112. ?> 
  113. </td> 
  114. </tr> 
  115. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  116. <td class="label"> 
  117. <label><?php _e("Display format", 'acf'); ?></label> 
  118. <p class="description"><?php _e("This format will be seen by the user when entering a value", 'acf'); ?></p> 
  119. <p><?php _e("\"dd/mm/yy\" or \"mm/dd/yy\" are the most used display formats. Read more about", 'acf'); ?> <a href="http://docs.jquery.com/UI/Datepicker/formatDate" target="_blank"><?php _e("jQuery date formats", 'acf'); ?></a></p> 
  120. </td> 
  121. <td> 
  122. <?php  
  123. do_action('acf/create_field', array( 
  124. 'type' => 'text',  
  125. 'name' => 'fields[' .$key.'][display_format]',  
  126. 'value' => $field['display_format'],  
  127. )); 
  128. ?> 
  129. </td> 
  130. </tr> 
  131. <tr class="field_option field_option_<?php echo $this->name; ?>"> 
  132. <td class="label"> 
  133. <label for=""><?php _e("Week Starts On", 'acf'); ?></label> 
  134. </td> 
  135. <td> 
  136. <?php  
  137.  
  138. $choices = array_values( $wp_locale->weekday ); 
  139.  
  140. do_action('acf/create_field', array( 
  141. 'type' => 'select',  
  142. 'name' => 'fields['.$key.'][first_day]',  
  143. 'value' => $field['first_day'],  
  144. 'choices' => $choices,  
  145. )); 
  146.  
  147. ?> 
  148. </td> 
  149. </tr> 
  150. <?php 
  151.  
  152.